views:

133

answers:

3

HI ,

i am having a table like

 <table id="toc" class="toc" border="1" summary="Contents">
 </table>

in many pages .. All these pages are rendered in a single page . when i apply the javascript to delete that using on load . Only one table is deleted and not the others

i am trying to delete the tables in all the rendering pages using javascript.how to do this?? Edit : I myself found the solution window.onLoad = load(); function load(){var tbl = document.getElementById('toc'); if(tbl) tbl.parentNode.removeChild(tbl);}

Thanks for everyone helped..

+3  A: 

Really want to delete the table altogether?

var elem = documenet.getElementById('toc');

if (typeof elem != 'undefined')
{
  elem.parentNode.removeChild(elem);
}

You could also hide the table rather than deleting it.

var elem = documenet.getElementById('toc');
elem.style.display = 'none';

If you need it later, you could simply do:

var elem = documenet.getElementById('toc');
elem.style.display = 'block';
Sarfraz
I think he's better off hiding it via a style
Pierreten
@Pierreten: Yes, it was important to post that. Thanks
Sarfraz
Only in somecases the table gets removed. but not all the times .. Y so ??
Aruna
+3  A: 

Here's a rough sample

<html>
<head>
<script type="text/javascript">

    function removeTable(id)
    {
        var tbl = document.getElementById(id);
        if(tbl) tbl.parentNode.removeChild(tbl);
    }

</script>
</head>
<body>

<table id="toc" class="toc" border="1" summary="Contents">
    <tr><td>This table is going</td></tr>
</table>

<input type="button" onclick="removeTable('toc');" value="Remove!" />

</body>
</html>
Jonathan
A: 
<script type="text/javascript">
  function deleteTable(){
    document.getElementById('div_table').innerHTML="TABLE DELETED"
  }
</script>

<div id="div_table">

 <table id="toc" class="toc" border="1" summary="Contents">
 </table>
</div>
<input type="button" onClick="deleteTable()">
Salil