javascript - How to detect any click on the page? -
i want catch click event on elements of page. can not catch click on specific page elements. see example https://jsfiddle.net/rdnf5m1f/
$(function() { $(".profile").on( "click","a", function() { console.log(1); return false; }); // below not work $("body").on( "click","*", function() { console.log(2); }); $("body").click(function() { console.log(2); }); $(window).click(function() { console.log(2); }); });
why?
following need "capture all, except some". add class 'nocapture' elements don't want capture, , use script:
jquery('*:not(.nocapture)').on('click', function(e){ e.stoppropagation(); console.log('element clicked', this); })
Comments
Post a Comment