Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't limit "return false" to parent element only; want children to return true!
    text
    copied!<p>This is my first time here so I hope I don't come off too stupid!</p> <p>I have a very simple jQuery problem: I have a database-generated ul-based navigation and I want list items that contain other lists to toggle showing those contained lists. The (generated) lists look like this (Wordpress code; ignore the Japanese):</p> <pre><code>&lt;div class="block first"&gt; &lt;ul class="counts"&gt; &lt;li class="cat-item cat-item-43"&gt; &lt;a href="http://localhost/crg/?cat=43" title="View all posts filed under その他制作物"&gt;その他制作物&lt;/a&gt; &lt;/li&gt; &lt;li class="cat-item cat-item-3"&gt; &lt;a href="http://localhost/crg/?cat=3" title="View all posts filed under クライアント"&gt;クライアント&lt;/a&gt; &lt;ul class='children'&gt; &lt;li class="cat-item cat-item-4"&gt; &lt;a href="http://localhost/crg/?cat=4" title="View all posts filed under マイクロソフト"&gt;マイクロソフト&lt;/a&gt; &lt;/li&gt; &lt;li class="cat-item cat-item-9"&gt; &lt;a href="http://localhost/crg/?cat=9" title="View all posts filed under 夢"&gt;夢&lt;/a&gt; &lt;/li&gt; &lt;li class="cat-item cat-item-8"&gt; &lt;a href="http://localhost/crg/?cat=8" title="View all posts filed under 生"&gt;生&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p></p> <p>And here's the jQuery I wrote to: First, hide all ul.children's inside li.cat-item's; Second, apply a toggle function and a return false to ONLY those li.cat-item's that have ul.children, leaving the links inside at their default function.</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { var children = $("li.cat-item:has(ul.children)&gt;ul.children").hide(); $("li.cat-item:has(ul.children)").click(function(){ $(this).find('ul.children').toggle(); return false; }); }); </code></pre> <p> </p> <p>The problem is, the "return false" is getting applied to everything inside the container li's and nothing I do seems to exclude them from the selection. Anybody know what I'm doing wrong?</p> <p>Thanks in advance</p>
 

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