开发者

Make jQuery dropdown toggle when click away?

I am using a jQuery drop down and I want the box to toggle when you click off the box

$(document).ready(function () {
  $('li.menu_head').mouseenter(function开发者_运维知识库 () {
    $('div.newsadviceDrop').slideToggle('medium');
  });
});

Can you help me?


I had to do something similar and the way I worked it out was to do something like

$('div.newsadviceDrop').click(function (e) {
    e.stopPropagation();
});
$(document).click(function() {
    ('div.newsadviceDrop').slideToggle('medium');
});

Basically, you need to toggle the menu if any other place is clicked, but if the actual location is clicked, you need to prevent the event from bubbling up to perform a toggle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜