I would say that definitely do not put a click handler on every element. As @Rin stated, you can assign them by tag or another selector.
If you really want to handle all the clicks on the page this way, I would suggest placing one handler on the document and letting the click events go to that.
This is much more efficient and there is no need to do e.stopPropagation() .
Example: http://jsfiddle.net/y6hry/
$(top.document).ready(function () { // All clicks on the page will bubble up to the document // and fire the handler. $(document).click(processAction); }); function processAction(e) { var clicked = e.target; alert(clicked.tagName); switch (clicked.tagName) { case "A": //execute code block 1 break; case "INPUT": //execute code block 2 break; default: //code to be executed if n is different from case 1 and 2 } };
source share