Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global jQuery `.click()`

I would like to fire an event when anything on the page is clicked, and then process normally. For example a click would be fired, I would see if the target matched something, alert if it did, and then have the click event continue (no preventDefault()).

like image 819
Josh K Avatar asked Jun 24 '10 14:06

Josh K


2 Answers

$(document).click(function(e) {
    // e.target is the element which has been clicked.
});

This will handle all click events unless a handler prevents the event from bubbling up (by calling the stopPropagation() method of the event object).

like image 60
ThiefMaster Avatar answered Nov 02 '22 17:11

ThiefMaster


$("body").click(function (event) {
// Your stuff here
}
like image 40
Mithun Sreedharan Avatar answered Nov 02 '22 19:11

Mithun Sreedharan