Does anybody know of a method to trigger an event in Prototype, as you can with jQuery's trigger function?
I have bound an event listener using the observe method, but I would also like to be able to fire the event programatically.
Thanks in advance
I don't think there is one built in to Prototype, but you can use this (not tested but should at least get you in the right direction):
The answers here are true for "Normal" events, that is events which are defined by the User Agent, but for custom events you should use prototype's "fire" method. e.g.
I found this post helpful... http://jehiah.cz/archive/firing-javascript-events-properly
It covers a way to fire events in both Firefox and IE.
event.simulate.js
fits your needs.I've used this several times and it works like a charm. It allows you to manually trigger native events, such as click or hover like so:
The great thing about this is that all attached event handlers will still be executed, just as if you would have clicked the element yourself.
For custom events you can use the standard prototype method
Event.fire()
.