...

View Full Version : Dynamically remove TD using javascript



mrbadboy
07-13-2007, 09:24 AM
Hi,

How to remove TD dynamically using javascript. I've mentioned below my code.

<table id="firstTbl" border="0" cellspacing="0" cellpadding="0" width="100%">
<tr id="firstTr">
<td id="firstTd"> </td>
<td id="secondTd"> </td>
</tr>
</table>

I need to remove "firstTd" from the table..

Can help me anybody.. ?


-Thanks

Kor
07-13-2007, 09:56 AM
...
var myTD=document.getElementById('firstTd');
myTD.parentNode.removeChild(myTD);
...

But, in fact, you don't need an id for the table elements, you may use the index of the cell in its row (or in the table)


...
var myTD=document.getElementById('firstTbl').getElementsByTagName('tr')[0].getElementsByTagName('td')[0];
myTD.parentNode.removeChild(myTD);
...

or


...
var myTD=document.getElementById('firstTbl').getElementsByTagName('td')[0];
myTD.parentNode.removeChild(myTD);
...

mrbadboy
07-13-2007, 11:37 AM
...
var myTD=document.getElementById('firstTd');
myTD.parentNode.removeChild(myTD);
...

But, in fact, you don't need an id for the table elements, you may use the index of the cell in its row (or in the table)


...
var myTD=document.getElementById('firstTbl').getElementsByTagName('tr')[0].getElementsByTagName('td')[0];
myTD.parentNode.removeChild(myTD);
...

or


...
var myTD=document.getElementById('firstTbl').getElementsByTagName('td')[0];
myTD.parentNode.removeChild(myTD);
...




Hi buddy,

Thanks for your reply.. ur codes r working properly..
i've tried with
document.getElementById("firstTr").removeChild(document.getElementById("firstTd"));
its also working...

Thanks and regards,
NM



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum