I am trying to something like very simple text editor. I need to provide functionality for the user to insert 7 different types of HTML elements and use them to create some custom form. Just to try how things work I made this:
<script type="text/javascript">
function MinMax() {
document.getElementById("EditorArea").innerHTML = "<table border= 1px><tr><td>Element</td><td><input type='textbox'/></td></tr><tr><td>Marked as</td><td><input type='textbox'/></td><tr><td>Min</td><td><input type='textbox'/></td><tr><td>Max</td><td><input type='textbox'/></td><tr><td>Преди ремонт</td><td><input type='textbox'/></td><tr><td>След ремонт</td><td><input type='textbox'/></td><tr><td>Time before</td><td><input type='textbox'/></td><tr><td>Time after</td><td><input type='textbox'/></td></table>";
//var elem = document.createElement("<table><tr><th>Firstname</th><th>Lastname</th></tr><tr><td>Peter</td><td>Griffin</td></table>");
};
function ShowDate() {
document.getElementById("EditorArea").innerHTML = "<p class='dateTime' style='width:120px; border: 2px solid black'>DateTime</p>";
}
</script>
</head>
<body>
<button type="button" onclick="MinMax()">MinMax</button>
<button type="button" onclick="ShowDate()">DateTime</button>
<div id="EditorArea" style = "width:800px; height:600px; border:2px solid black;">
The problem I have is that I can't find a way to add a whole table structure using insertBefore or insertAfter. However innerHTML does it but when I add another element it removes the previous. Even though I still don't know how I will let the user arrange the different elements to make it look like he wants, for now I need a way to add several elements without this behavior - the old element to be removed by the new one.
