开发者

Making jQuery slideUp when clicking off

I am using jQuery to make a nav slideDown. I want when people click anywhere outside of the nav it slideUp.

The problem is that with my code it slideUp even if I click on the element. I basically want it to slideUp if the user clicks anywhere other than the element which slideDown

 //News Drop Down
$(document).ready(function () {
$('li.newsDrop').mouseenter(function () {
    $('div.newsadviceDrop').slideDown('medium');
});
});

$('bo开发者_如何学JAVAdy').click(function() {
    $('div.newsadviceDrop').slideUp('slow', function() {
    // Animation complete.
   });
});


This it wath I would do:

$('*').not("li.newsDrop").click(function() {
    $('div.newsadviceDrop').slideUp('slow', function() {
    // Animation complete.
});


$(':not([attr="value"])').click(function() {
$('div.newsadviceDrop').slideUp('slow', function() {
// Animation complete.

});

in not your li element..so the other elements besides your li would be selected

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜