Remove all the DOM elements with a specific tag name in Javascript - Javascript DOM

Javascript examples for DOM:Element removeChild

Description

Remove all the DOM elements with a specific tag name in Javascript

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <div>
         one//  ww w . j  av a2 s.  c o m
      </div> 
      <div>
         two 
         <div>
            three
         </div> 
      </div> 
      <div>
         four
      </div> 
      <script>
Array.prototype.slice.call(document.getElementsByTagName('div')).forEach(function(item) { 
   item.parentNode.removeChild(item); 
} );

      </script>  
   </body>
</html>

Related Tutorials