how to find an element based on two selectors?

i have a doom tree like this:

ul #navigation
    li .active
    ul
        li.active_li
        li
        li
    /ul
    li
    ul
        li.active_li
        li
        li
    /ul
/ul

i would like to find the li with a class of active_li inside the ul belonging to the li that has a class of active. :)

as we can see there are 2 li with a class of active_li. i want only the first one

something like: $('#navigation').find('li.active').find('li.active)li').doSomething();

this selector doesn't seem to work

any ideas?

Answers


Try this selector:

$('#navigation li.active ul li.active_li')
                         ^^
                          \_ You can get rid of this, as <li> elements
                             exist only within <ul> elements.

You can use

$('#navigation li.active li.active_li').each(function(){

});

and flag the function off after running the first one.

Or if you just want the first one selected:

 $('#navigation li.active li.active_li').first();

Need Your Help

How to tear down wcf service after each web service call

vb.net wcf

I inherited a working WCF Web Service with one major flaw - the WCF Service consumes memory and does not release unless the service is restarted. After a half a day of requests hitting the web ser...