David Dashifen Kees wrote:
> What's the best method for swapping two table rows? For instance,
> assume you have the following table:
>
> <table>
> <tr>
> <td>1</td>
> <td><img src="down.gif"></td>
> </tr>
> <tr>
> <td>2</td>
> <td><img src="up.gif"></td>
> </tr>
> </table>
>
> What I want to do is swap the two table rows when someone clicks an
> image. I thought for sure that things would be golden when I started
> looking at the Insertion.Before object, but so far it's yielded no joy
You need only use the native javascript method insertBefore():
tbody.insertBefore(secondTr,firstTr);
With insertBefore(), when the DOM node given in the first argument is
already in the document tree it is simply moved. Full working example
below.
--Ken
working example:
<table>
<tbody id="tbody">
<tr id="first">
<td>1</td>
<td><img src="down.gif"></td>
</tr>
<tr id="second">
<td>2</td>
<td><img src="up.gif"></td>
</tr>
</tbody>
</table>
<script>
function $(id) {
return document.getElementById(id);
}
$('tbody').insertBefore($('second'),$('first'));
</script>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---