I’m writing jQuery for an app that’s being build in JSF. The JSF components are using a lot of their own JS for doing whatever JSF does and they use a lot of onclick attributes to handle it all.
Is there valid/proper way to bind your own click event to an element and ensure that your event fires prior to the default onclick event? It appears that by default a jQuery click function is fired after any inline onclick function calls.
In jQuery events are triggered strictly in the order in which they were registered.
You can circumvent any inline DOM0
onclickstyle handlers by iterating over the whole DOM, removing thoseonclickproperties, and then registering your own handler which then invokes the originally defined function.Something like:
See http://jsfiddle.net/alnitak/2SCTK/
So, register your own handlers first with jQuery, then invoke the code above to remove the original inline
onclickhandlers and re-register them as if jQuery had added them.EDIT code simplified to just use the original function – jQuery will ensure that the function is invoked with the right context. Previous code which explicitly set the context to
windowwas incorrect.