View Full Version : how to use cloneNode

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?


10-03-2002, 07:21 PM
i figured it out.
it goes:
var el=document.getElementById("abomb").cloneNode();

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).

10-05-2002, 05:34 AM
I may be wrong here, but I believe


will not create the sibling relationship you wanted. I think


would do it.

:rolleyes: .... so I guess


would make them cousins :D

10-05-2002, 11:39 AM

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)

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 ...


10-06-2002, 10:15 AM

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum