How To Make Jquery Submenu Stay Visible After It Is Clicked? -


i have read similar posts not jquery need more specific menu.

<div id="nav"><!--// start nav //-->     <dl id="nav">         <dt class="nav"><b>one</b></dt>         <dd>             <ul>                 <li><a href="/a">a</a></li>                 <li><a href="/b">b</a></li>                 <li><a href="/c">c</a></li>              </ul>         </dd>         <dt class="nav"><b>two</b></dt>         <dd>             <ul class="nav">                 <li><a href="/d">d</a></li>                 <li><a href="/e">e</a></li>                  <li><a href="/f">f</a></li>                 </ul>         </dd>      </dl>         </div><!--// end nav //--> 

here js using.

<script type="text/javascript"> $(document).ready(function(){     if($("#nav")) {         $("#nav dd").hide();         $("#nav dt.nav b").click(function() {             if(this.classname.indexof("clicked") != -1) {                 $(this).parent().next().slideup(200);                 $(this).removeclass("clicked");             }             else {                 $("#nav dt.nav b").removeclass();                 $(this).addclass("clicked");                 $("#nav dd:visible").slideup(200);                 $(this).parent().next().slidedown(500);             }             return false;         });     } }); </script> 

thanks

the menu hides due pagerefresh. can avoid it, adding click handler, returns false. add code ready handler:

$("#nav dd ul a").click(function(){     return false; }) 

here example.

update:

you can store selected url in cookies. here sample:

$(document).ready(function() {     if ($("#nav")) {         $("#nav dd").hide();         $("#nav dt.nav b").click(function() {             if (this.classname.indexof("clicked") != -1) {                 $(this).parent().next().slideup(200);                 $(this).removeclass("clicked");             }             else {                 $("#nav dt.nav b").removeclass();                 $(this).addclass("clicked");                 $("#nav dd:visible").slideup(200);                 $(this).parent().next().slidedown(500);             }             return false;         });     }      $("#nav dd ul a").click(function() {         $.cookie('link_href', $(this).attr('href'));     });      alert($.cookie('link_href'));      var selector = 'a[href="'+ $.cookie('link_href') +'"]';     $(selector).parents('dd').prev().find('b').click(); }); 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -