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
精彩评论