0

I want to remove all the childNodes from the javascript object. I referred W3Schools example. But they are using while loop and remove child node one by one. See the below code.

var list = document.getElementById("myList");

// As long as <ul> has a child node, remove it
while (list.hasChildNodes()) {   
    list.removeChild(list.firstChild);
}

W3Schools Link.

I have more than 1000 childNodes. So i want to remove it in single steps. Using while loop will get performance issue. Any one help on this.

Thanks, Bharathi.

Bharathi
  • 1,288
  • 2
  • 14
  • 40

1 Answers1

2

Simply remove innerHtml of the element to get rid of all the childnodes

document.getElementById("myList").innerHTML = ""
gurvinder372
  • 66,980
  • 10
  • 72
  • 94