Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find if LI has children UL
    primarykey
    data
    text
    <p>I have the following structure:</p> <pre><code>&lt;ul&gt; &lt;li class="static"&gt; &lt;ul class="static"&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="static"&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>As you can see the first LI element has UL inside it but the next one doesn't. Is there a way to find out through jquery if a certain LI has UL inside it or not? I want to do something like this:</p> <pre><code>if(li has children ul) { do something } </code></pre> <p><strong>EDIT</strong></p> <p>I tried the following but it shows "YES" for all cases. Here's my code and HTML. In the HTML below, only "Link2" contains child UL and not Link1 and Link3. I just want to do some operation when a user clicks on some LI which contain child UL.</p> <p><strong>CODE</strong></p> <pre><code>$('#DeltaPlaceHolderLeftNavBar div &gt; div &gt; ul &gt; li &gt; a').click(function() { if($('li:has(&gt; ul)')) alert("yes"); else alert("no"); }); </code></pre> <p><strong>HTML</strong> </p> <pre><code>&lt;div class="ms-core-navigation" id="DeltaPlaceHolderLeftNavBar"&gt; &lt;div id="ctl00_PlaceHolderLeftNavBar_QuickLaunchNavigationManager"&gt; &lt;div class=" noindex ms-core-listMenu-verticalBox" id="zz14_V4QuickLaunchMenu"&gt; &lt;ul class="root ms-core-listMenu-root static" id="zz15_RootAspMenu"&gt; &lt;li class="static"&gt; &lt;a href="link1.php" tabindex="0" class="someclass1"&gt; &lt;span class="someclass2"&gt; &lt;span class="menu-item-text"&gt;Link1&lt;/span&gt; &lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li class="static"&gt; &lt;a href="link2.aspx" tabindex="0" class="someclass3"&gt; &lt;span class="someclass2"&gt; &lt;span class="menu-item-text"&gt;Link2&lt;/span&gt; &lt;/span&gt; &lt;/a&gt; &lt;ul class="static"&gt; &lt;li class="static"&gt; &lt;a href="Link2A.php" tabindex="0" class="someclass1"&gt; &lt;span class="someclass2"&gt; &lt;span class="menu-item-text"&gt;Link2A&lt;/span&gt; &lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;li class="static"&gt; &lt;a href="Link2B.php" tabindex="0" class="someclass1"&gt; &lt;span class="someclass2"&gt; &lt;span class="menu-item-text"&gt;Link2B&lt;/span&gt; &lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="static"&gt; &lt;a href="Link3.php" tabindex="0" class="someclass1"&gt; &lt;span class="someclass2"&gt; &lt;span class="menu-item-text"&gt;Link3&lt;/span&gt; &lt;/span&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload