ASAAKI
10-03-2002, 03:49 PM
i have a div, "abomb" that i want to clone. there is nothing on the page besides this div, and i don't want any depth in the hierarchy. i want the clone to just be a sibling of 'abomb'. how do i do it?
:confused:
ASAAKI
10-03-2002, 07:21 PM
i figured it out.
it goes:
var el=document.getElementById("abomb").cloneNode();
document.body.appendChild(el);
Alex Vincent
10-05-2002, 03:31 AM
:) If abomb has any children (stuff inside the element, such as text or other elements), you want to use cloneNode(true).
brothercake
10-05-2002, 05:34 AM
I may be wrong here, but I believe
document.body.appendChild(el);
will not create the sibling relationship you wanted. I think
document.getElementById("abomb").parentNode.appendChild(el);
would do it.
:rolleyes: .... so I guess
document.getElementById("abomb").previousSibling.appendChild(el);
would make them cousins :D
ASAAKI
10-05-2002, 11:39 AM
document.getElementById("abomb").parentNode.appendChild(el);
yea that looks right. but if 'abomb' is the only thing on the page, then 'body' is after all its parentNode, so i guess document.body.appendChild(el) and the above one are pretty much the same thing ... or aren't they?
by the way, i couldn't get any cousins because 'abomb' doesn't have any previous siblings...:) if it did, though, i don't think appending a child to the previous sibling would keep the hierarchy flat, it would make 'abomb' el's uncle (or aunt ... :D)
brothercake
10-06-2002, 03:33 AM
I didn't see the bit about only have that node on the page - in that case, yes, it amounts to the same thing.
And you're right - it would be cousin/uncle.
document.getElementById("me").previousFlatmate.nextLover.parentNode.stepSister ...
:rolleyes: