Jump to content
Larry Ullman's Book Forums

simon

Members
  • Posts

    2
  • Joined

  • Last visited

simon's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Thanks for looking at that HartleySan. I'm trying to stay away from libraries for the moment. I did see today that there is an API for traversing documents as trees of elements while ignoring text nodes. It's not implemented in IE though. Here's what I've been playing around with. It seems to work, but doesn't test for nextElementSibling or previousElementSibling: /*jslint browser: true*/ /*global U*/ /** * Return the nth sibling element of Element e. * If n is positive, return the nth next sibling element. * If n is negative, return the nth previous sibling element. * If n is 0, return e. * **/ function sibling(e, n) { 'use strict'; while (e && n !== 0) { if (n > 0) { // Find the next element sibling. // If e is not a text node (nodeType !== 1) // find the next sibling and decrement n by 1. if (e && e.nodeType !== 1) { e = e.nextSibling; n = n - 1; } else { // If e exists it's a text node. // Try the next sibling. Do not decrement. e = e.nextSibling; } } else { // Find the previous element sibling. if (e && e.nodeType !== 1) { e = e.previousSibling; n = n + 1; } else { e = e.previousSibling; } } } return e; } - based on Javascript - The Definitive Guide (pages 372 - 374)
  2. Thanks... I just had the exact same problem (using firefox.) David's solution worked for me, but I am now looking at different ways to refer to the span element as the DOM traversal method seems too risky. Simon I've settled on this for now: target.parentNode.getElementsByTagName('span')[0].style.visibility = 'visible';
×
×
  • Create New...