HTML DOM removeChild() Method

The removeChild() method is used to removes a specified child of the specified element. The syntax of removeChild() method is as follows :
  elementNode.removeChild(node)
where the node represent the object you want to remove.
<html>
<body>
  <ul id="list">
    <li>First List</a></li>
    <li>Second List</a></li>
    <li>Third List</li>
    <li>Fourth List</li>
  </ul>
  <button onclick="myfunc()">Click Here</button>
  <script>
    function myfunc() {
      var elem = document.getElementById('list');
      elem.removeChild(elem.childNodes[1]);
    }
  </script>
</body>
</html>
Output :

  • First List
  • Second List
  • Third List
  • Fourth List


Next Topic :