It's not only possible, it's trivial:
document.body.addEventListener("click", function(e) {
// Use e.target for the clicked element
}, false);
Clicks "bubble" from the clicked element to its parent, then its parent, then its parent, etc., until they reach the document. (Unless an intervening event handler stops that via e.stopPropagation
.) The above hooks the click on body
(the container of all of your visible elements).
Note that the above works on all modern browsers, including IE9 and up in standards mode. It does not work on IE8 and earlier (or IE9 and later pretending to be IE8 or earier) because they didn't have addEventListener
. You'd have to use the IE-specific attachEvent
instead.