How do i re-assign a parentNode

Discussion in 'Javascript' started by daveyand, Sep 15, 2006.

  1. daveyand

    daveyand Guest

    Hey guys

    I have a 2 table rows with 2 cells each. Cell 0 of each row has a
    select.

    E.g.

    <tr id="row_0">
    <td id="cell_0">
    <select id=select_1> <option>SELECT 1<option></select>
    </td>
    <td id="cell_1">
    <select id=select_2> <option>SELECT 2</option></select>
    </td>
    </tr>

    What i am trying to do is switch the two select boxes round. So cell_0
    will have the select with an id of select_2 and not select_1.

    But i dont want to do innerHTML, as the selects are in an array of
    select references. (All abit complicated i guess)

    So i wanted to go down the

    document.getElementById(select_2).parentNode =
    document.getElementById(cell_0);

    I have tried this but it doesnt seem to work.

    Does anyone know of a way to do this?

    Cheers

    Andy

    p.s. Hope it makes sense./...
     
    daveyand, Sep 15, 2006
    #1
    1. Advertising

  2. daveyand

    RobG Guest

    daveyand wrote:
    > Hey guys
    >
    > I have a 2 table rows with 2 cells each. Cell 0 of each row has a
    > select.
    >
    > E.g.
    >
    > <tr id="row_0">
    > <td id="cell_0">
    > <select id=select_1> <option>SELECT 1<option></select>
    > </td>
    > <td id="cell_1">
    > <select id=select_2> <option>SELECT 2</option></select>
    > </td>
    > </tr>
    >
    > What i am trying to do is switch the two select boxes round. So cell_0
    > will have the select with an id of select_2 and not select_1.
    >
    > But i dont want to do innerHTML, as the selects are in an array of
    > select references. (All abit complicated i guess)
    >
    > So i wanted to go down the
    >
    > document.getElementById(select_2).parentNode =
    > document.getElementById(cell_0);
    >
    > I have tried this but it doesnt seem to work.
    >
    > Does anyone know of a way to do this?


    Abbreviated for posting:

    var gE = document.getElementById;
    gE('cell_0').appendChild(gE('select_2'));
    gE('cell_1').appendChild(gE('select_1'));


    --
    Rob
     
    RobG, Sep 15, 2006
    #2
    1. Advertising

  3. daveyand

    Tom Cole Guest

    RobG wrote:
    > daveyand wrote:
    > > Hey guys
    > >
    > > I have a 2 table rows with 2 cells each. Cell 0 of each row has a
    > > select.
    > >
    > > E.g.
    > >
    > > <tr id="row_0">
    > > <td id="cell_0">
    > > <select id=select_1> <option>SELECT 1<option></select>
    > > </td>
    > > <td id="cell_1">
    > > <select id=select_2> <option>SELECT 2</option></select>
    > > </td>
    > > </tr>
    > >
    > > What i am trying to do is switch the two select boxes round. So cell_0
    > > will have the select with an id of select_2 and not select_1.
    > >
    > > But i dont want to do innerHTML, as the selects are in an array of
    > > select references. (All abit complicated i guess)
    > >
    > > So i wanted to go down the
    > >
    > > document.getElementById(select_2).parentNode =
    > > document.getElementById(cell_0);
    > >
    > > I have tried this but it doesnt seem to work.
    > >
    > > Does anyone know of a way to do this?

    >
    > Abbreviated for posting:
    >
    > var gE = document.getElementById;
    > gE('cell_0').appendChild(gE('select_2'));
    > gE('cell_1').appendChild(gE('select_1'));


    Just for my education, appending a child to a node automatically
    "removes" it from the existing path and adds it to the new path? That
    would make sense as a single node can't belong to two paths. Correct?

    >
    >
    > --
    > Rob
     
    Tom Cole, Sep 15, 2006
    #3
  4. daveyand

    Ian Collins Guest

    Tom Cole wrote:
    > RobG wrote:
    >
    >>
    >>Abbreviated for posting:
    >>
    >> var gE = document.getElementById;
    >> gE('cell_0').appendChild(gE('select_2'));
    >> gE('cell_1').appendChild(gE('select_1'));

    >
    >
    > Just for my education, appending a child to a node automatically
    > "removes" it from the existing path and adds it to the new path? That
    > would make sense as a single node can't belong to two paths. Correct?
    >

    Yes, if you want to copy a node rather than move it, you have to use
    cloneNode.

    --
    Ian Collins.
     
    Ian Collins, Sep 16, 2006
    #4
  5. daveyand

    RobG Guest

    Tom Cole wrote:
    [...]
    > Just for my education, appending a child to a node automatically
    > "removes" it from the existing path and adds it to the new path? That
    > would make sense as a single node can't belong to two paths. Correct?


    "appendChild
    "Adds the node newChild to the end of the list of children of this
    node. If the newChild is already in the tree, it is first removed."
    <URL: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-184E7107 >


    --
    Rob
     
    RobG, Sep 16, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    3,449
  2. NotGiven
    Replies:
    0
    Views:
    508
    NotGiven
    Sep 17, 2004
  3. RC
    Replies:
    1
    Views:
    1,311
    Martin Honnen
    May 31, 2007
  4. pxpilot

    XmlNode ParentNode???

    pxpilot, Feb 23, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    467
    Michael Nemtsev [MVP]
    Feb 23, 2008
  5. Michael Hill

    Trying to Find the ParentNode

    Michael Hill, Jan 15, 2004, in forum: Javascript
    Replies:
    3
    Views:
    100
    Richard Cornford
    Jan 18, 2004
Loading...

Share This Page