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

How do i re-assign a parentNode

P: n/a
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./...

Sep 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

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

Sep 15 '06 #2

P: n/a

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
Sep 15 '06 #3

P: n/a
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.
Sep 16 '06 #4

P: n/a

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-Cor...ml#ID-184E7107 >
--
Rob

Sep 16 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.