469,929 Members | 1,790 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

nextSibling & previousSibling under Mozilla

I wrote a following function just for testing purposes:
<html>
<head>
<script>
function show(obj) {
alert(obj.previousSibling.rowIndex)
alert(obj.rowIndex)
alert(obj.nextSibling.rowIndex)
}
</script>
</head>
<body>
<table>
<tr >
<td></td><td></td></tr>
<tr onclick="show(this)">
<td>1</td><td>something</td></tr>
<tr onclick="show(this)">
<td></td><td></td></tr>
<tr onclick="show(this)">
<td>2</td><td>something</td></tr>
<tr onclick="show(this)">
<td></td><td></td></tr>
<tr onclick="show(this)">
<td>3</td><td>something</td></tr>
<tr>
<td></td><td></td></tr>
</table>
</form>
</body>
</html>

Under MSIE it seems to work correctly, while when run under Mozilla 1.6 it
returns "undefined" for previousSibling and nextSibling, is there any way
of accessing neighbour rows from a "this" row under Mozilla?
Jul 20 '05 #1
1 6860


PaweƂ GaƂecki wrote:
I wrote a following function just for testing purposes:
<html>
<head>
<script>
function show(obj) {
alert(obj.previousSibling.rowIndex)
alert(obj.rowIndex)
alert(obj.nextSibling.rowIndex)
}
</script>
</head>
<body>
<table>
<tr >
<td></td><td></td></tr>
<tr onclick="show(this)">
<td>1</td><td>something</td></tr>
<tr onclick="show(this)">
<td></td><td></td></tr>
<tr onclick="show(this)">
<td>2</td><td>something</td></tr>
<tr onclick="show(this)">
<td></td><td></td></tr>
<tr onclick="show(this)">
<td>3</td><td>something</td></tr>
<tr>
<td></td><td></td></tr>
</table>
</form>
</body>
</html>

Under MSIE it seems to work correctly, while when run under Mozilla 1.6 it
returns "undefined" for previousSibling and nextSibling, is there any way
of accessing neighbour rows from a "this" row under Mozilla?


No, you don't test for previousSibling or nextSibling, you are testing for
previousSibling.rowIndex
and that is undefined as previousSibling of your <tr> element is a text
node and not an element node in Mozilla's document object model. This is
a common misunderstanding, IE throws out all whitespace between elements
that authors use for formatting/indenting while Mozilla models them as
text nodes.
So you need to make sure that you look at the right node, for instance
var sibling = obj.nextSibling;
while (sibling && sibling.nodeType != 1) {
sibling = sibling.nextSibling;
}
if (sibling) {
// access sibling.rowIndex
}
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Patrick | last post: by
3 posts views Thread by ReGenesis0 | last post: by
12 posts views Thread by BillKi | last post: by
5 posts views Thread by 2obvious | last post: by
1 post views Thread by Asad | last post: by
14 posts views Thread by Arne | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.