How do i re-assign a parentNode

D

daveyand

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./...
 
R

RobG

daveyand said:
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'));
 
T

Tom Cole

RobG said:
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?
 
I

Ian Collins

Tom said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top