4 ms·
When you start to treat HTML as element nodes and child-nodes instead of "strings" things get not only more secure but also much easier to maintain. Use node.ap
by z3t4 10y ago
When you start to treat HTML as element nodes and child-nodes instead of "strings" things get not only more secure but also much easier to maintain. Use node.appendChild and document.createTextNode! Code example:
function myButton(parentNode) {
var button = document.createElement("button");
button.appendChild(document.createTextNode("Click me"));
parentNode.appendChild(button);
button.onclick = function click() {
button.appendChild(document.createTextNode(" more!"));
}
}