molendijk
04-12-2010, 01:25 PM
I'm testing the following script for including and removing HTML:
<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>
I'd like to replace the line in red with a line using valid DOM.
Any suggestions?
===
Arie Molendijk.
<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>
I'd like to replace the line in red with a line using valid DOM.
Any suggestions?
===
Arie Molendijk.