javascript to move a DIV using the DOM

G

Graham Charles

I'm trying to move a DIV element to before one of its siblings using a
javascript function.

This works fine on most browsers:

function putdivbefore(divtomove, divtarget)
{
var mydiv1 = document.getElementById(divtarget);
var mydiv2 = document.getElementById(divtomove);
mydiv1.parentNode.insertBefore(mydiv2, mydiv1);

}


On IE, however, it gives spotty results. In a simple test page it
works fine, but when the page is more complex, it causes the browser
to stop loading the page and return "Operation was aborted."

Can anyone point me to a resource for this?

Thanks,

g.
 
T

Thomas 'PointedEars' Lahn

Graham said:
I'm trying to move a DIV element to before one of its siblings using a
javascript function.

This works fine on most browsers:

function putdivbefore(divtomove, divtarget)
{
var mydiv1 = document.getElementById(divtarget);
var mydiv2 = document.getElementById(divtomove);
mydiv1.parentNode.insertBefore(mydiv2, mydiv1);

}

On IE, however, it gives spotty results. In a simple test page it
works fine, but when the page is more complex, it causes the browser
to stop loading the page and return "Operation was aborted."

What do you mean by "stop loading"? Are you saying that you are trying
to modify the document tree while the document is still loading? Weird
behavior would not be surprising then.

If yes, which would explain why it works with short/simple documents (they
load fast enough and have less to be parsed), wait until the `load' event
of the document occurs before you modify the document tree.


PointedEars
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top