SPRBRN
SPRBRN

Reputation: 2462

Jquery select div inside ul which has a span

Take the following code:

<ul class="menu">
    <li class="section">
        <span class="show">ABC</span>
        <ul class="items"><li>UL selected</li></ul>
    </li>
     <li class="section">
        <span class="">DEF</span>
        <ul class="items"><li>UL not selected</li></ul>
    </li>
</ul>

I need to select each ul.items inside a li.section which has a span with class "show". In this example, only the first ul.items should be selected.

What jquery selector do I need?

Upvotes: 5

Views: 3248

Answers (2)

dvir
dvir

Reputation: 5115

This could do the trick (http://jsfiddle.net/bmqyF/1/):

$("ul li.section:has(span.show) ul.items li");

Upvotes: 7

Kokos
Kokos

Reputation: 9121

$('li.section:has(span.show) ul.items')

Finds the li.section's that have span.show and selects the ul.items within it.

Upvotes: 1

Related Questions