Moving a div from inside one div to another div using Prototype?

后端 未结 4 1937
盖世英雄少女心
盖世英雄少女心 2020-12-28 18:25

In prototype or normal-but-cross-browser-compatible Javascript, how do I move the contents of a div to the contents of another div?

Inside the div is a form with ids

4条回答
  •  离开以前
    2020-12-28 18:32

    To move the contents of here into there, you're basically after:

    $('there').insert($('here').childNodes);
    

    Sadly, that doesn't work.

    As with the other two answers, it looks like you have to resort to plain JavaScript with prototype only providing a shorthand for document.getElementById.

    var frag = document.createDocumentFragment();
    for (var c = $('nav').firstChild, n; c; c = n) {
        n = c.nextSibling;
        frag.appendChild(c);
    }
    $('header').appendChild(frag);
    

    (See John Resign's blog for performance stats on DocumentFragments: http://ejohn.org/blog/dom-documentfragments/)

提交回复
热议问题