Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nextSibling Issue 1

Status
Not open for further replies.

bean1234

Technical User
Nov 14, 2006
45
US
Hello All,

I am calling a javascrip function showHideAll as in the below code, the problem is that this.nextSibling always returns undefined.Please look at the following markup, by this.nextSibling I want to refer to teh next anchor tag <a>.

Code:
<a href="#" onclick="showHideAll(this.parentNode.parentNode,[b]this.nextSibling[/b]);return false;"><img src="./../resources/images/button_expcoll.gif; align="middle" width="9" height="10"></a>&nbsp;<a href="#" onclick="showHideAll(this.parentNode.parentNode,this);return false;">Expand All</a>
 </a>
 
your next sibling is the &nbsp;.

what you'll need to do is either 1) remove the &nbsp; from the code and instead use css to provide the spacing gap or 2) use a loop to find the next anchor sibling, rather than just the next sibling. i'd opt for #1.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Personally I would have chosen option 2. If you ever go back and edit your code, maybe space it out to read it easier, your going to break your javascript then spend an additional three days trying to figure out what you did originally and why it is broken.
Maintainable code after the fact is often less expensive then the extra 15-20 minutes of coding up front to make something maintainable.

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top