333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

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

103 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Won a competition
  • Made it to the Authors' Hall of Fame
+7 more
DOTonPAPER says

Try $(‘ul’, this)

333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

Try $(‘ul’, this)
It doesn’t work. Thanks
40 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
oscardog says

Surely:

$(this).find(‘ul’)

Would do the trick?

347 posts
  • Won a Most Wanted contest
  • Won a competition
  • Located in Netherlands
  • Has sold $40,000+ on Envato Market
+6 more
RikdeVos says

Like oscardog said: $(this).find(‘ul’)

For your second question:
$(".this").click(function() {
   $(this).find("ul")
});
2 posts
  • Sells items exclusively on Envato Market
  • Located in Slovakia
  • Has been part of the Envato Community for over 3 years
  • Won a Most Wanted contest
+3 more
Mioo says

How can I target all <ul> elements that are inside $(this)?
$(this).find("ul");

Now when I click on the li with the class “this” how can I target all the ul’s inside of this list?
at first how to target:
$(".this").find("ul")...;
or
$(".this ul")...;

...and with the click event:

$(".this").click(function(){
    $(this).find("ul")...;
});
333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

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.

40 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
oscardog says

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.

333 posts
  • Has referred 100+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
vtimbuc says

I will stay with this, because I need the anchor tag there.

Thank you all for the help ;)

40 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
oscardog says

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!

by
by
by
by
by
by