wierd nextSibling problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gregerly
    Recognized Expert New Member
    • Sep 2006
    • 192

    wierd nextSibling problem

    I'm trying to access the next sibling of a <li> which happens to be another <li> The code looks like this:

    Code:
    <div id='tutorials'>[INDENT]<ul>[INDENT]<li>Some List</li>
    <li class='Desc'  id='RANDOMID'>Some Content</li>
    <li>Intro to AJAX</li>
    <li>Real World CSS</li>[/INDENT]
    </ul>[/INDENT]
    </div>
    And the Javascript:

    Code:
     	var tutorialDiv=document.getElementById("tutorials");
    	var tutorialLI=tutorialDiv.getElementsByTagName("li");
    	for(var i=0; i<tutorialLI.length; i++){
    		tutorialLI[i].onclick=function(){
    			alert(this.nextSibling.getAttribute("id"));
    		}
    	}
    Basically, when an LI in the tutorialDiv is clicked, I want to access the next sibling (which is another LI, with more information about the LI clicked on) and toggle the visibility (using scriptaculous, but that's not my problem). In IE 7, I get the alert above just fine, alerting "RANDOMID" after clicking the first LI, but in FireFox, I get an error: "this.nextSibli lng.getAttribut e is not a function" . Any idea why it would work in IE but not firefox?

    Thanks in advance

    Greg
  • gregerly
    Recognized Expert New Member
    • Sep 2006
    • 192

    #2
    found the problem. in firefox, you can't have a new line in order to access the nextSibling with javascript, IE it has to be:

    Code:
    <li>first sibling</li><li>nextSibling</li>
    NOT

    Code:
    <li>first sibling</li>
    <li>nextSibling</li>

    Comment

    Working...