Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-03-2002, 03:49 PM   PM User | #1
ASAAKI
Regular Coder

 
Join Date: Jul 2002
Location: This little Earth.
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
ASAAKI is an unknown quantity at this point
Question how to use cloneNode

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?

__________________
'If you don't stand for something, you'll fall for anything.'
ASAAKI is offline   Reply With Quote
Old 10-03-2002, 07:21 PM   PM User | #2
ASAAKI
Regular Coder

 
Join Date: Jul 2002
Location: This little Earth.
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
ASAAKI is an unknown quantity at this point
i figured it out.
it goes:
var el=document.getElementById("abomb").cloneNode();
document.body.appendChild(el);
__________________
'If you don't stand for something, you'll fall for anything.'
ASAAKI is offline   Reply With Quote
Old 10-05-2002, 03:31 AM   PM User | #3
Alex Vincent
Moderator


 
Join Date: May 2002
Location: Hayward, CA
Posts: 1,427
Thanks: 1
Thanked 19 Times in 17 Posts
Alex Vincent is on a distinguished road
If abomb has any children (stuff inside the element, such as text or other elements), you want to use cloneNode(true).
__________________
"The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
June 30, 2001
author, Verbosio prototype XML Editor
author, JavaScript Developer's Dictionary
https://alexvincent.us/blog
Alex Vincent is offline   Reply With Quote
Old 10-05-2002, 05:34 AM   PM User | #4
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
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.

.... so I guess

document.getElementById("abomb").previousSibling.appendChild(el);

would make them cousins

Last edited by brothercake; 10-05-2002 at 05:36 AM..
brothercake is offline   Reply With Quote
Old 10-05-2002, 11:39 AM   PM User | #5
ASAAKI
Regular Coder

 
Join Date: Jul 2002
Location: This little Earth.
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
ASAAKI is an unknown quantity at this point
Quote:
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 ... )
__________________
'If you don't stand for something, you'll fall for anything.'
ASAAKI is offline   Reply With Quote
Old 10-06-2002, 03:33 AM   PM User | #6
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
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 ...

brothercake is offline   Reply With Quote
Old 10-06-2002, 10:15 AM   PM User | #7
ASAAKI
Regular Coder

 
Join Date: Jul 2002
Location: This little Earth.
Posts: 383
Thanks: 0
Thanked 0 Times in 0 Posts
ASAAKI is an unknown quantity at this point
lol
__________________
'If you don't stand for something, you'll fall for anything.'
ASAAKI is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:10 AM.


Advertisement
Log in to turn off these ads.