Wednesday, February 27, 2013

Hide dropdown on clicking outside when using JQuery Toggle

This is slightly better, as it also check the parent(s) of the element being clicked:
$(document).click(function(e) {
    var target = e.target;

    if (!$(target).is('#menu') && !$(target).parents().is('#menu')) {
        $('#menu').hide();
    }
});

No comments:

Post a Comment