I want a generic (cross browser) way to get the browser to execute the default action
for an object for a specified event preferably without getting any attached listeners to fire.
This kind of question has been asked before but in the context of already being in an event, and/or strictly talking about synchronously holding off the default action before letting it happen later.
Basically, let's say you have an DOM element (you don't know which) variable, and you want to invoke a click
, such that if it were an anchor
, it'd follow its href
, if it were an input[type="submit"]
it would submit the form.
But without firing that element's listeners for the click
event (which may be prone preventDefault()
s in the listeners).
For those that need a reason to answer questions; you may want to do it if you're implementing something like dispatchEvent()
for browsers that only have fireEvent()
.
Both functions return true
if the default wasn't 'prevented', but only dispatchEvent()
actually follows through and invokes the default.
As a side question, jQuery's trigger()
is meant to do this (although after firing the listeners) and be cross-browser, maybe the solution is there? As nice as jQuery is I'd like to know the vanilla methods it is calling (if it [this particular feature] indeed works on things like IE8).