Make a jQuery element slide up if clicked anywhere outside of it
I have a drop down that I want to slideup when clicked anywhere outside of it (and all it's child elements)
My code seems to not be working :(
$(docum开发者_如何学JAVAent).ready(function () {
$('*').not(".drop").click(function() {
$('.drop').slideUp('medium', function() {
// Animation complete.
});});});
Try this I hope this will help you.
$(document).ready(function () {
$('.drop').click(function(e){
e.stopPropagation();
});
$('html').click(function() {
var $drop = $('.drop');
if($drop.is(":visible")) {
$drop.slideUp('medium', function() {
// Animation complete.
});
}
});
});
$(document).click(function() {
if ($('.drop').is(':visible'))
$('.drop').slideUp();
});
$(".drop").click(function() {
$('.drop').slideDown();
return false;
});
精彩评论