...

View Full Version : flip node order



brothercake
04-28-2003, 06:00 PM
I've got a bunch of nodes - a list:


<ul>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ul>

What's the quickest / easiest way of rearranging those nodes so they go 4-3-2-1?

Would it perhaps be possible to prototype something like a sort() method for node structures?

liorean
04-28-2003, 09:12 PM
The easiest would be to determine the wanted order, and append them to parentNode using appendChild in that order.

The most efficient would be only moving those necessare to move, but that would take more calculation in turn,

jkd
04-28-2003, 09:14 PM
Create a swap node function, and then do (pseudo-code-ish):

for (i = 0; i < parseInt(length/2); i++)
swap(i, length-1-i);

brothercake
04-29-2003, 03:59 PM
Thanks - tis pretty much what I had in mind



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum