On Feb 19, 6:40 am, Aitor Garay-Romero <aito...@gmail.com> wrote:
> Hi there!
>
>   I need to remove an arbitray element from the DOM and add it later
> exactly to the same point in the DOM.  I wonder is there is a direct
> way to achieve this.  Right now i have to check wether the element has
> a previous sibling or directly a parent and remember this information
> to add it back.

Fairly simple: remember the parentNode and nextSibling, then re-insert
the node using parent.insertBefore(node, nextSibling).  If there is no
nextSibling, it will be null and the element will be inserted as the
last child of the parent.  Otherwise, it will use the nextSbling.

e.g.

  function reInsert(id) {
    var el = document.getElementById('xx');
    var nextSib = el.nextSibling;
    var parent = el.parentNode;
    parent.removeChild(el);
    setTimeout( function() {
      parent.insertBefore(el, nextSib);
    }, 1000);
  }


Call the function, pass it an ID.  The element will be removed, then
about 1 second later it will be put back.  Modify to suit.

*Do not* use Prototype.js's sibling array as it will remove text
nodes, you certainly don't want to do that.


--
Rob
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to