jquery - Hide menu onClick -


i have dropdown menu, slidedown whenever users click on link. however, don't know how make slideup, whenever user click somewhere on page (not on menu of course).

my css looks this:

<li class="da-header-button message">     <span class="da-button-count">32</span>     <a href="#">notifications</a>     <ul class="subnav">         <li class="head"><span class="bold">notificatons</span></li>         <li class="item"><a href="#">under menu</a></li>         <li class="item"><a href="#">under menu</a></li>     </ul> </li> 

my current jquery code looks this:

jquery("ul.topnav li").click(function() { //when trigger clicked...       //following events applied subnav (moving subnav , down)       jquery(this).find("ul.subnav").slidedown('fast').show(); //drop down subnav on click       jquery(this).hover(function() {       }, function(){           jquery(this).find("ul.subnav").slideup('slow'); //when mouse hovers out of subnav, move       });   }); 

if edit last jquery function this: jquery(this).hover(function() this: jquery(this).click(function() not work, since slidedown , right after.

thank help.

edit:

thanks guys! if have 2 of these submenus open @ same time? how can prevent this?

i want allow have 1 open.

slide visible menus when click propagates document:

$(document).on("click", function(){     $(".subnav:visible").slideup(); }); 

then prevent happening when you're within menus stopping event propagation.

$("ul.topnav").on("click", "li", function(e){     e.stoppropagation();     $(".subnav:visible", $(this).siblings()).slideup("fast");     $(".subnav", this).slidedown(); }); 

fiddle: http://jsfiddle.net/jonathansampson/qqsdn/


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -