use element.parentNode.removeChild to remove an element - Javascript DOM

Javascript examples for DOM:Element removeChild

Description

use element.parentNode.removeChild to remove an element

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script type="text/javascript">
    function removeTable(id)
    {// w w w .  j av  a2  s.c o  m
        var tbl = document.getElementById(id);
        if(tbl) 
           tbl.parentNode.removeChild(tbl);
    }

      </script> 
   </head> 
   <body> 
      <table id="toc" class="toc" border="1" summary="Contents"> 
         <tbody>
            <tr>
               <td>This table is going</td>
            </tr> 
         </tbody>
      </table> 
      <input type="button" onclick="removeTable('toc');" value="Remove!">  
   </body>
</html>

Related Tutorials