Javascript examples for DOM:Element hasChildNodes
Element hasChildNodes Method - Remove the first child node (index 0) inside an <ul> element, if the element has any child nodes:
<!DOCTYPE html> <html> <body> <ul id="myList"><li>Coffee</li><li>Tea</li></ul> <button onclick="myFunction()">Test</button> <script> function myFunction() {//w ww .ja va 2 s . c o m var list = document.getElementById("myList"); if (list.hasChildNodes()) { list.removeChild(list.childNodes[0]); } } </script> </body> </html>