Y
yawnmoth
Given an element ID, is there a way to figure out what index one would
need to use in the parentNode's childNodes array to get at that
element?
For example...
<body>
<div id="parent">
<div id="a">a</div>
<div id="b">b</div>
<div id="c">c</div>
</div>
<script type="text/javascript">
alert(document.getElementById('a').parentNode.childNodes[0].innerHTML);
</script>
</body>
The index that IE uses (0) isn't the same as the index that Firefox
uses (1). How could I find this out given an element ID?
As for why I'm asking... I'm writting a script some of whose elements
are not going to be in any predictable order. I'd like to give each of
these elements their own unique ID and then figure out each of their
indexes to their collective parents (they all have the same parent)
childNodes array. This will allow the HTML to be aware of the order of
these elements even though the server side script, itself, isn't.
The above script doesn't really seem relevant, at first, to this
problem, but if I can solve the problem in the above script, I think I
should be able to solve the problem in the actual script I'm working
on.
Anyway, any ideas would be appreciated - thanks!
need to use in the parentNode's childNodes array to get at that
element?
For example...
<body>
<div id="parent">
<div id="a">a</div>
<div id="b">b</div>
<div id="c">c</div>
</div>
<script type="text/javascript">
alert(document.getElementById('a').parentNode.childNodes[0].innerHTML);
</script>
</body>
The index that IE uses (0) isn't the same as the index that Firefox
uses (1). How could I find this out given an element ID?
As for why I'm asking... I'm writting a script some of whose elements
are not going to be in any predictable order. I'd like to give each of
these elements their own unique ID and then figure out each of their
indexes to their collective parents (they all have the same parent)
childNodes array. This will allow the HTML to be aware of the order of
these elements even though the server side script, itself, isn't.
The above script doesn't really seem relevant, at first, to this
problem, but if I can solve the problem in the above script, I think I
should be able to solve the problem in the actual script I'm working
on.
Anyway, any ideas would be appreciated - thanks!