By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,842 Members | 2,440 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,842 IT Pros & Developers. It's quick & easy.

DOM element move

P: n/a
gsb
I have created a div tag and appended it as a child to the document body.

Obj=document.createElement('DIV');
Obj=document.body.appendChild(Obj);

Is there a way to move the object w/o deleting it and creating a new one?

Maybe a remove and appendBefore or appendAfter?

gsb
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"gsb" <gs*@QWest.net> writes:
I have created a div tag and appended it as a child to the document body.

Obj=document.createElement('DIV');
Obj=document.body.appendChild(Obj);
No need to assign the return value of "appendChild" to Obj. It returns
the appended node, which is already the value of Obj.
Is there a way to move the object w/o deleting it and creating a new one?
Any new insertion will move it. A DOM node can only occour once in a
document, so inserting it a new place will remove it from its previous
location.
Maybe a remove and appendBefore or appendAfter?


No need to remove. Just insertBefore where you need it.
someToBeParentNode.insertBefore(Obj,someNewSibling );

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
DU
gsb wrote:
I have created a div tag and appended it as a child to the document body.

Obj=document.createElement('DIV');
Obj=document.body.appendChild(Obj);

Is there a way to move the object w/o deleting it and creating a new one?

Maybe a remove and appendBefore or appendAfter?

gsb

insertBefore:
http://www.w3.org/TR/2000/REC-DOM-Le...l#ID-952280727

removeChild:
http://www.w3.org/TR/2000/REC-DOM-Le...#ID-1734834066

DU

Jul 20 '05 #3

P: n/a
Create a new DIV where you want to move the current object then
use 'oldDiv = Object.replaceChild(newDiv, oldDiv)';

I hope this has been helpful.

--
************************************
MUSIC24SEVEN
Pioneers of the
'Digital Entertainment Industry'
http://music24seven.com
************************************
"gsb" <gs*@QWest.net> wrote in message
news:e8****************@news.uswest.net...
I have created a div tag and appended it as a child to the document body.

Obj=document.createElement('DIV');
Obj=document.body.appendChild(Obj);

Is there a way to move the object w/o deleting it and creating a new one?

Maybe a remove and appendBefore or appendAfter?

gsb

Jul 20 '05 #4

P: n/a
gsb
Thanks all.

gsb
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.