WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 nextSibling, Kenneth Solberg, February 26, 2004
     Re:nextSibling , Brian R. James, February 27, 2004
     Re:nextSibling, Guilherme Blanco, February 27, 2004

Subject: Re:nextSibling From: Brian R. James Date: February 27, 2004

In your instance, e.nextSibling is returning a textNode not the UL element.  This is because your UL element is not placed immediately to the right of your A (anchor) element, but on the next line.  Between the UL and A elements is a hidden/whitespace textNode.  textNodes do not have a tagName property, hence your problem.  Either you can call nextSibling twice like Guilherme suggested, or use a while loop to iterate through nextSibling until a valid element node is found.

Brian R. James

From: Kenneth Solberg
Sent: Feburary 26, 2004
Subject: Re:nextSibling

Consider this markup fragment:

  <a href="#">Online Resources</a>
   <ul class="nav_lvl4">
     <li><a href="#">Accessories</a></li>

And this piece of script:

document.onclick = va_nav;
function va_nav()
{
var e = window.event.srcElement;
  var s = e.nextSibling;
  alert(s.tagName);
}

Why doesn't the alert show "UL" when I click the anchor?

Thanks in advance!

Kenneth Solberg
Tape International AS





Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX