Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery detects click on level 1 menu item when clicking level 2 menu items
    primarykey
    data
    text
    <p>I have this html menu. Some menu items have a submenu.</p> <pre><code>&lt;ul class="menu uppercase"&gt; &lt;li class="mitem"&gt;Level 1 Menu Item &lt;ul class="submenu"&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="mitem"&gt;Level 1 Menu Item &lt;ul class="submenu"&gt; &lt;li class="smitem"&gt;Name of Collection&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;li class="smitem"&gt;Level 2 Menu Item&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="mitem"&gt;Level 1 Menu Item&lt;/li&gt; &lt;li class="mitem"&gt;Level 1 Menu Item&lt;/li&gt; &lt;li class="mitem"&gt;Level 1 Menu Item&lt;/li&gt; </code></pre> <p></p> <p>The Jquery Looks like this.</p> <pre><code>$("li.mitem").click(function(){//when menu item is clicked $("ul.submenu").slideUp();//hide all sub menus $("li.mitem").css('margin-bottom','0px').css('border-left','none');//reset margin bottom and left border $(this).css('border-left','1px solid #E0E0E0').css('padding-left','9px');//add border and padding to this menu item $(this).children("ul.submenu").slideDown();//show menu items child sub menu $(this).children().children("li.smitem:first").css('padding-top','18px');//add padding to first sub menu item if($(this).children().length&gt;0){ $(this).css('margin-bottom','18px'); } }); </code></pre> <p>So basically, when you click on a level 1 menu item it displays the submenu for that menu item by sliding it down. when you click on the next level 1 menu item if slides up the current sub menu and slides down the next sub menu. </p> <p>However.... and the problem is... When you click on a level 2 menu item it slides up the sub menu and then back down again.</p> <p>I believe this is happening because the sub menu is within the li of the level 1 menu.</p> <p>How can i stop this? Its an unexpected behaviour.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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