I'm testing the following script for including and removing HTML:
I'd like to replace the line in red with a line using valid DOM.Code:<script type="text/javascript"> function remove(id) { while(document.getElementById(id).firstChild) {document.getElementById(id).removeChild(document.getElementById(id).firstChild);} } function include(which,id){ var newdiv = document.createElement("div"); newdiv.innerHTML = which; remove(id); document.getElementById(id).appendChild(newdiv); } </script> </head> <body> <div id="test"></div> <a onclick='include(whatever,"test");'>add</a><br> <a onclick='remove("test")'>remove</a><br> </body>
Any suggestions?
===
Arie Molendijk.



Reply With Quote
Bookmarks