Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 452
SPRBRN Avatar asked Oct 10 '11 09:10

SPRBRN


2 Answers

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

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

like image 192
Dvir Avatar answered Sep 29 '22 05:09

Dvir


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

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

like image 22
Kokos Avatar answered Sep 29 '22 05:09

Kokos