It can be confirmed that inline handlers are run because it is explicitly coded:
handle = ontype && cur[ ontype ];
if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) {
event.preventDefault();
}
where ontype
is in this case "onclick"
. So it is fetching the onclick
property 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 an if
block:
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
// ...
elem[ type ]();
where onlyHandlers
is true
for triggerHandle
and false
for .trigger
, and therefore triggerHandler
does not execute e.g. elem.click()
(whereas .trigger
does). 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
.