jQuery trigger event when click outside the element

Just have your menuWraper element call event.stopPropagation() so that its click event doesn’t bubble up to the document.

Try it out: http://jsfiddle.net/Py7Mu/

$(document).click(function() {
    alert('clicked outside');
});

$(".menuWraper").click(function(event) {
    alert('clicked inside');
    event.stopPropagation();
});
  • http://api.jquery.com/event.stopPropagation/

Alternatively, you could return false; instead of using event.stopPropagation();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)