Note that there are some explanatory texts on larger screens.

plurals
  1. POKeeping menu extension open on page change
    primarykey
    data
    text
    <p>I have an expanding menu using jquery. It works well except for one thing: when the user navigates away from the page the menu collapses. I want the menu to stay open when the user clicks on any of the final &lt; li > links. All of these links open the same page. Content on these pages is grabbed from a database and determined by the ?id=.</p> <p>Here's the code:</p> <p>HTML:</p> <pre><code> &lt;ul id="nav"&gt; &lt;li&gt;&lt;a href="javascript:;"&gt;Products&lt;/a&gt; &lt;ul id="nav2"&gt; &lt;li&gt;&lt;a href="javascript:;"&gt;Domestic Market&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="index.php?page=Product&amp;id=1"&gt;Link1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="index.php?page=Product&amp;id=2"&gt;Link2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="index.php?page=Product&amp;id=3"&gt;Link3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="javascript:;"&gt;Commercial Market&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=""&gt;Coming Soon&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>CSS:</p> <pre><code>ul { padding: 0px; margin: 0px; width: 10em; list-style-type:none; } li { font: 100% Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#003; } li ul { display: none; } li.active &gt; ul { display: block; } </code></pre> <p>jQuery:</p> <pre><code>$('#nav').delegate('li,a', 'click', function(e) { e.stopPropagation(); var self = $(e.target), //get a reference to the clicked element active = self.parents().andSelf() //select all li's that should be active .addClass('active'); //and activate them $('#nav .active').not(active).removeClass('active'); //deactivate others }); $(document).click(function(){ $('.active').removeClass('active'); }); </code></pre> <p>How do I keep the final &lt; li >'s open?</p>
    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