Delete all children nodes
To remove all children nodes (from childNodes list) use:
Of course innerHTML will work too:
while(listNode.firstChild) { // delete all nodes listNode.removeChild(listNode.firstChild); }
Of course innerHTML will work too:
listNode.innerHTML = '';
Thanx, you are a lifesaver!
ReplyDeleteUsed your code to remove all children except the firs one, consider the following example:
var prvyoption=document.getElementById('searchinfo');
while (elm.searchsel.firstChild)
{
elm.searchsel.removeChild(elm.searchsel.firstChild);
}
elm.searchsel.options[0]=prvyoption;
simple, isn't it? :)
Thanks for the tip!
ReplyDelete