How can i add an createElement(br)
before and after the table? I tried it with doc.body.appendChild(p);
at the end, but nothing happens. i don't know where i have to write the appendchild
function insertBlock(border)
{
var doc = document.getElementById("frame").contentWindow.document;
var p = doc.createElement("br");
var range = doc.getSelection().getRangeAt(0);
myParent=document.getElementById("frame").contentWindow.document.body;
if (border == true)
{
myTable=document.createElement("table");
myTable.setAttribute("style","border: 1px solid #000000;");
}
else
{
myTable=document.createElement("table");
}
// IE5, IE6 benoetigen unbedingt tbody-Element
myTBody=document.createElement("tbody");
myRow=document.createElement("tr");
myCell=document.createElement("td");
myText=document.createTextNode("Die erste Zelle");
myCell.appendChild(myText);
myRow.appendChild(myCell);
myCell=document.createElement("td");
myText=document.createTextNode("Die zweite Zelle");
myCell.appendChild(myText);
myRow.appendChild(myCell);
myTBody.appendChild(myRow);
myTable.appendChild(myTBody);
myParent.appendChild(myTable);
range.insertNode(myTable);
}
`'s should be a thing of the past. Also, with this amount of DOM manipulation, I would also try looking at a templating library like Handlebars. http://handlebarsjs.com/ – arjabbar Apr 10 '15 at 21:35