469,270 Members | 1,633 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Push a DOM element down one level?

I want to take a document that contains a number of tables and wrap the
tables inside new elements. I have tried something similar to the
following:

tparent = table.parentNode;
wrapper = document.createElement('DIV');
wrapper.appendChild(table);
tparent.replaceChild(wrapper,table);

This doesn't seem to work though (tested in Safari).

--
Kevin Smith
Ke*********@sas.com
Jul 20 '05 #1
1 1523
Kevin Smith <Ke*********@sas.com> writes:
I want to take a document that contains a number of tables and wrap the
tables inside new elements. I have tried something similar to the
following:

tparent = table.parentNode;
wrapper = document.createElement('DIV');
wrapper.appendChild(table);
A DOM node can only have one parent. At this point, you *move* the
table into the wrapper ...
tparent.replaceChild(wrapper,table);


.... so it is no longer a child of tparent.

Try switching the operations:

tparent = table.parentNode;
wrapper = document.createElement('DIV');
tparent.replaceChild(wrapper,table);
wrapper.appendChild(table);

/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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Markus Ernst | last post: by
3 posts views Thread by Andrew Phillipo | last post: by
1 post views Thread by Rob Griffiths | last post: by
7 posts views Thread by giangiammy | last post: by
4 posts views Thread by Ben Kim | last post: by
4 posts views Thread by TycoonUK | last post: by
4 posts views Thread by kj7ny | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.