473,416 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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 7082


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Patrick | last post by:
Hi I am in the process of learning javascript and was wondering how often the web professionals update I.E & N.N? I mean do you religiously wait for the next upgrade and download it ASAP when...
5
by: Jukka K. Korpela | last post by:
The HTML specifications define the entities &zwj;, &zwnj;, &lrm;, &rlm; as denoting zero-width joiner, zero-width non-joiner, left to right mark, and right to left mark. Is there any evidence of...
3
by: ReGenesis0 | last post by:
I'm trying to rewrite the existing window using javascript. This works fine in IE- but in Mozilla, after I call a window.open, Mozilla starts wandering around like an alshiemers patient and...
12
by: BillKi | last post by:
I am trying to use nextSibling to move focus to the next input (text box). Here's the script: function CheckFieldLength(e, i) { // don't move automatically forward if a tab or shift-tab was...
5
by: 2obvious | last post by:
During the window.onload event, I set the .onclick event of an element to turn off the display of the first two elements in a <div> called "content": var objNode =...
1
by: Asad | last post by:
I am trying to get the PreviousSibling function work. But I keep getting the error (Error accessing XML). Here is my code: ...
6
by: Marc | last post by:
This is probably a no brainer for the most of you but my head is spinning at the moment. Considering the following list how do I get a reference to the ul just below the li with id products?...
2
by: VK | last post by:
Is there any functional or contextual difference between elemRef.firstChild and elemRef.nextSibling ? From MDC I did not get any.
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.