I’ve made this test code for the question: https://jsfiddle.net/5phqm/1/
As far as I understand, if jQuery’s triggerHandler() prevents default browser behavior, then native JavaScript events will not be triggered and handled (and it’s true for addEventListener() in my code), but inline event, added through tag’s attribute onclick="" will be triggered anyway! Why it happens? Am I misunderstanding something about events triggering in browser?
It can be confirmed that inline handlers are run because it is explicitly coded:
where
ontypeis in this case"onclick". So it is fetching theonclickproperty of the element and then executing it. This piece of code is always called, regardless of.trigger/.triggerHandler.Native actions however, like
elem.click(), are only executed inside anifblock:where
onlyHandlersistruefortriggerHandleandfalsefor.trigger, and thereforetriggerHandlerdoes not execute e.g.elem.click()(whereas.triggerdoes). As such, the native action is prevented.So inline handlers and native actions are separate things and are also handled separately. Only native actions are prevented by
.triggerHandler.