Push a DOM element down one level?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Smith

    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.parentNod e;
    wrapper = document.create Element('DIV');
    wrapper.appendC hild(table);
    tparent.replace Child(wrapper,t able);

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

    --
    Kevin Smith
    Kevin.Smith@sas .com
  • Lasse Reichstein Nielsen

    #2
    Re: Push a DOM element down one level?

    Kevin Smith <Kevin.Smith@sa s.com> writes:
    [color=blue]
    > 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.parentNod e;
    > wrapper = document.create Element('DIV');
    > wrapper.appendC hild(table);[/color]

    A DOM node can only have one parent. At this point, you *move* the
    table into the wrapper ...
    [color=blue]
    > tparent.replace Child(wrapper,t able);[/color]

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

    Try switching the operations:

    tparent = table.parentNod e;
    wrapper = document.create Element('DIV');
    tparent.replace Child(wrapper,t able);
    wrapper.appendC hild(table);

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...