Remove all child nodes of a list:
Click the button to remove all child nodes of ul.
<!DOCTYPE html> <html> <body> <ul id="myList"><li>CSS</li><li>HTML</li><li>Java</li></ul> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w w w. ja va 2 s. co m*/ var list = document.getElementById("myList"); while (list.hasChildNodes()) { list.removeChild(list.firstChild); } } </script> </body> </html>