javascript - Event capturing jQuery -


i need capture event instead of letting bubble. want:

<body>    <div>    </div> </body> 

from sample code have click event bounded on div , body. want body event called first. how go this?

use event capturing instead:-

$("body").get(0).addeventlistener("click", function(){}, true); 

check last argument "addeventlistener" default false , in event bubbling mode. if set true work capturing event.

for cross browser implementation.

var bodyele = $("body").get(0); if(bodyele.addeventlistener){    bodyele.addeventlistener("click", function(){}, true); }else if(bodyele.attachevent){    document.attachevent("onclick", function(){        var event = window.event;    }); } 

ie8 , prior default use event bubbling. attached event on document instead of body, need use event object target object. ie need tricky.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -