Note that there are some explanatory texts on larger screens.

plurals
  1. POKeep menu open after clicking sub-item jQuery
    primarykey
    data
    text
    <p>I've searched and not found exactly what I was looking for.</p> <p>I have my menu working with cookies so when the page is reloaded it keeps the menus that were open, open.</p> <p>But I realised when you click say a sub-item of Hyperlink 2 it will close Hyperlink 2 altogether. Is there a way too keep it open?</p> <p><a href="http://jsfiddle.net/Dnamixup/5S54v/" rel="nofollow noreferrer">http://jsfiddle.net/Dnamixup/5S54v/</a></p> <p>I tried using the simulate click answer from <a href="https://stackoverflow.com/questions/11904879/jquery-to-toggle-sub-menu-but-keep-sub-menu-open-if-sub-menu-page-active">Here</a> but it didn't work unless I placed it wrong.</p> <p>I'm still new at javascript/jQuery but I'm slowly getting it!</p> <p>Thank you</p> <pre><code>&lt;ul class="nav"&gt; &lt;li&gt;&lt;a&gt;Hyperlink 1&lt;/a&gt; &lt;/li&gt; &lt;li class="drop"&gt;&lt;a&gt;Hyperlink 2&lt;/a&gt; &lt;ul id="m1"&gt; &lt;li&gt;&lt;a href="#"&gt;Hyperlink Sub&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Hyperlink Sub&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="drop"&gt;&lt;a&gt;Hyperlink 3&lt;/a&gt; &lt;ul id="m2"&gt; &lt;li&gt;&lt;a href="#"&gt;Hyperlink Sub&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Hyperlink Sub&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li class="drop"&gt;&lt;a&gt;Hyperlink 4&lt;/a&gt; &lt;ul id="m3"&gt; &lt;li&gt;&lt;a href="#"&gt;Hyperlink Sub&lt;/a&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Hyperlink Sub&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; </code></pre> <p></p> <pre><code>jQuery(function ($) { // jQuery code in here can safely use $ $('.nav li') .css({ cursor: "pointer" }); $(".drop") .on('click', function () { $(this).toggleClass('open'); $(this).find('ul').toggle(); $.cookie('open_items', 'the_value'); openItems = new Array(); $("li.drop").each(function (index, item) { if ($(item).hasClass('open')) { openItems.push(index); } }); $.cookie('open_items', openItems.join(',')); }); if ($.cookie('open_items') &amp;&amp; $.cookie('open_items').length &gt; 0) { previouslyOpenItems = $.cookie('open_items'); openItemIndexes = previouslyOpenItems.split(','); $(openItemIndexes).each(function (index, item) { $("li.drop").eq(item).addClass('open').find('ul').toggle(); }); } }); </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.
    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