I have this structure:
<ul>
<li>
<a> link .. </a>
<span>开发者_C百科; text </span>
<ul>
...
</ul>
</li>
...
I'm adding a click event on both the <span>
and <a>
elements and I'm trying to select the nested <ul>
using $(this).next("ul");
It works for the span, but not for the link. What am I doing wrong here?
A click handler on the anchor will not see the UL if you're using next
to grab it, since next
will only select the very next sibling. You can try:
$("a").nextAll("ul").hide();
or:
$("a").parent().find("ul").hide();
or:
$("a").siblings("ul").hide();
精彩评论