Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery check if clicked li has child ol/ul
    primarykey
    data
    text
    <p>Looking for a solution on how to detect if a li has a child ul or ol i discovered jquerys <a href="http://api.jquery.com/has/" rel="nofollow">has()</a> which is pretty awesome apart from I need to detect if only the actual clicked li has a child ol, not any of its siblings. Are there any ways of doing this? The documentation doesnt cover this.</p> <p><strong>HTML</strong></p> <pre><code> &lt;ol&gt; &lt;li&gt;&lt;a class="delete-li" href=""&gt;Page 1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="delete-li" href=""&gt;Page 2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="delete-li" href=""&gt;Page 3 has ol&lt;/a&gt; &lt;ol&gt; &lt;li&gt;&lt;a class="delete-li" href=""&gt;Page 4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="delete-li" href=""&gt;Page 5&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="delete-li" href=""&gt;Page 6&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/li&gt; &lt;/ol&gt; </code></pre> <p><strong>JS</strong></p> <pre><code>$('.delete-li').live('click', function(event){ event.preventDefault(); item_id = $(this).attr('rel'); clicked = $(this); //////////////////// //check if has sub pages if(clicked.has('ol')){ answer = confirm('This will delete all sub pages and content are you sure?'); console.log(answer); if(answer===true){gogogo=true; }else{gogogo=false;} }else{ gogogo=true;} //if yes run AJAX delete if(gogogo===true){ alert('LI REMOVED'); } //////////////// }); </code></pre> <p>Checkout the <a href="http://jsfiddle.net/ZqzVN/" rel="nofollow">jsfiddle</a> for the code.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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