Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can't get 'nextSibling' to work

    This works for me in IE6, but not FF1.0:

    (Alert! This question is cross posted here :
    http://www.webdeveloper.com/forum/sh...threadid=54082
    but an answer doesn't seem to be forthcoming.)

    Code:
    <html>
    </style>
    <script type="text/javascript" language="javascript">
    <!-- Hide from browsers without javascript
    
    window.onload=function()
    {
    	alert(document.getElementById("d1").nextSibling.id);
    };
    
    // End hiding -->
    </script>
    </head>
    <body>
    
    <div id="d1">text1</div>
    <div id="d2">text2</div>
    
    </body>
    </html>

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    It will work in Moz also if you remove the empty space like this:

    <div id="d1">text1</div><div id="d2">text2</div>

    The problem is that Moz (otherwise a correct interpretation) sees the possible textNode (even if an empty space)as the nextSibling, not the next <div> (as IE does)

    Search the Forum for a code (I remeber I've seen it somewere) to "remove" empty spaces for Moz.

    Or use the reference by tag name rather than firstChild or nextSibling...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Nov 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Someone on the other forum posted what the problem was: Moz sees a carriage return between two <divs> like this:

    <div>some text</div>(invisible carriage return)
    <div>other text</div>

    so the nextSibling of the first <div> is a text node containing the invisible carriage return, which is a pretty ridiculous implementation in my opinion.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    it is the same thing as I said, but in other words. No, it is not really a silly implementation, it is an exact implementation of w3c recomandations. Moz keeps the ideea that before each tag child of a parent may be inserted a textNode, thus the order is

    parent
    textNode0
    tagChild0
    textNode1
    tagChild1
    textNode2
    tagChilde2
    /parent

    This case, you see that parent.firstChild is the textNode0, not the tagChild0, even if the textNode is empty (in fact an empty space) . The same with parent.tagChild0.nextSibling, which is textNode1, not tagChild1, even if the textNode is empty.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Spurious text node generation preserves indentation in the DOM representation. Try serializing a DOM in IE, then do the same thing in Mozilla. You'll notice Mozilla's is actually readable.
    Last edited by jkd; 01-19-2005 at 03:37 PM.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the code to get rid of them, if you need to -- http://www.codingforums.com/showthre...ead.php?t=7028
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •