[Javascript] I have hit a brick wall
Scott Reynen
scott at randomchaos.com
Thu Sep 7 11:16:43 CDT 2006
On Sep 7, 2006, at 10:33 AM, Terry Riegel wrote:
> I need soemthing similar to the swapNodes() function you wrote
> yesterday.
>
> This is my humble (non-working) attempt so far.
>
>
> function rippleNodes(a,k)
> {
> var placeHolder = document.createElement(k);
> var i=document.getElementById(a[0])
> for (x=0; x<a.length; x++)
> {
> if (x==0)
> {
> i.parentNode.replaceChild(placeHolder,i)
> }
> else
> {
> var n=document.getElementById(a[x])
> var n1=document.getElementById(a[x-1])
> n.parentNode.replaceChild(n1,n)
> }
> }
> placeHolder.parentNode.replaceChild(i, placeHolder);
> }
How about this (untested):
function bubbleUpNodes(a) // where a is array of IDs
{
for ( x=1; x<a.length; x++) // bubble first to last by swapping
adjacent nodes and IDs throughout the array
{
var tempId = a[x-1]; // prepare to swap IDs
swapNodes( document.getElementById(a[x-1]) , document.getElementById
(a[x]) ); // swap nodes
a[x-1] = a[x]; // swap IDs
a[x] = tempId; // swap IDs
}
}
Peace,
Scott
More information about the Javascript
mailing list