javascript - JQuery - Stopping Event Bubbling in all Browsers -


i have massively nested gui controls - when they're clicked or changed or whatever need stop event going further dom tree. needs work across browsers.

at point i've got rather clunky js code:

//do in response original user action //leave @ that. try {         e.stoppropagation();     }     catch (ex) {      }     try {         event.cancelbubble();     }     catch (ex) {      }      try {         event.preventdefault();     }     catch (ex) { } ... 

this work, smells , feels wrong (personally loathe empty catch blocks). there neater x-browser trick can use?

if use jquery event.stoppropagation() work fine. jquery unifies event handling.

in general if, want test special browser methods, can so:

if(event.stoppropagation) {     event.stoppropagation(); } else if... 

this jquery doing. creates wrapper event , provides unified interface.

the name of event object defined you. event object passed first argument event handler. have setup event handler accept parameter, e.g.:

$('selector').click(function(foo) { // event, e, bar, whatever want     foo.stoppropagation(); }); 

typically e or event used.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -