Hey guys,
How can I target all <ul> elements that are inside $(this)?
Ex:<ul class="first">
<li></li>
<li class="this">
<ul class="second">
<li></li>
<li>
<ul class="third">
<li></li>
<li>
<ul class="etc"></ul>
</li>
<li></li>
</ul>
</li>
<li></li>
</ul>
</li>
<li></li>
</ul>
Now when I click on the li with the class “this” how can I target all the ul’s inside of this list?
Thanks
Try $(‘ul’, this)
MariusCristianDonea saidIt doesn’t work. Thanks
Try $(‘ul’, this)
Surely:
$(this).find(‘ul’)
Would do the trick?
Like oscardog said: $(this).find(‘ul’)
$(".this").click(function() {
$(this).find("ul")
});
- Slovakia
- Has been a member for 1-2 years
- Exclusive Author
- Sold between 10 000 and 50 000 dollars
- Most Wanted Bounty Winner
- Referred between 1 and 9 users
- Bought between 1 and 9 items
downv said
How can I target all <ul> elements that are inside $(this)?
$(this).find("ul");
downv saidat first how to target:
Now when I click on the li with the class “this” how can I target all the ul’s inside of this list?
$(".this").find("ul")...;
or
$(".this ul")...;
...and with the click event:
$(".this").click(function(){
$(this).find("ul")...;
});I can’t get it to work ..
I have the click event on a anchor tag, maybe this is why it doesn’t work..
http://jsfiddle.net/kpKUG/21/Edit: I think I’ve found the solution, will test it on the script.
You’re right, sort of. The problem is because it’s on the link and thus it has no children. You can simply select the parent list item and then search for other ULs:
http://jsfiddle.net/kpKUG/22/There are obviously other ways of doing it, but that will work. Personally I’d just put the click event on the list item rather than the link and then just use CSS to make it look like a link if required.
I will stay with this, because I need the anchor tag there.
Thank you all for the help 
downv said
I will stay with this, because I need the anchor tag there. Thank you all for the help![]()
You don’t need to remove the anchor tag, you can keep that and in the href just put “javascript:void” (some people use hashes but those throw you to the top of the page so I avoid them). Then you just switch the event to the list item and voila, you save one more function call which is always nice for performance (even if it’s a tiny increase!) 
And your welcome!
