javascript to move a DIV using the DOM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Graham Charles

    javascript to move a DIV using the DOM

    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(di vtomove, divtarget)
    {
    var mydiv1 = document.getEle mentById(divtar get);
    var mydiv2 = document.getEle mentById(divtom ove);
    mydiv1.parentNo de.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.
  • Thomas 'PointedEars' Lahn

    #2
    Re: javascript to move a DIV using the DOM

    Graham Charles wrote:
    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(di vtomove, divtarget)
    {
    var mydiv1 = document.getEle mentById(divtar get);
    var mydiv2 = document.getEle mentById(divtom ove);
    mydiv1.parentNo de.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
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

    Comment

    • Bjoern Hoehrmann

      #3
      Re: javascript to move a DIV using the DOM

      * Graham Charles wrote in comp.lang.javas cript:
      >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."
      You may be experiencing a problem like this:

        http://blogs.msdn.com/ie/archive/200...n-aborted.aspx

      Also see the documents linked from there.
      --
      Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
      Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
      68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

      Comment

      Working...