How to swap two rows using JS + DOM ?

T

Timmy

Hi guy,

consider the following table:



<table id="t" border="0" width="200">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
</table>



how to swap row 2 with row 1, using DOM (not innerHTML!)

thanks...
 
D

Daniel Kirsch

Timmy said:
<table id="t" border="0" width="200">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td>3</td>
</tr>
</table>



how to swap row 2 with row 1, using DOM (not innerHTML!)

Have you read the "DIV around TR" thread from this morning?

var table = document.getElementById("t");
table.rows[0].parentNode.insertBefore(table.rows[1],table.rows[0]);

You need to use parenNode and not just the table object, as the UA
inserts a tbody element between <table> and the <tr> elements.

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top