Delete all children nodes

To remove all children nodes (from childNodes list) use:

while(listNode.firstChild) { // delete all nodes

Of course innerHTML will work too:

listNode.innerHTML = '';


  1. Thanx, you are a lifesaver!
    Used your code to remove all children except the firs one, consider the following example:

    var prvyoption=document.getElementById('searchinfo');
    while (elm.searchsel.firstChild)

    simple, isn't it? :)


Post a Comment

Popular posts from this blog

Data visualization for Roadmap Microsite (Angular and D3.js)

Conceptual design

Four tools for prototyping: Sketch, Figma, Principle, and FramerX