Read more

Trigger an event with Javascript

Henning Koch
November 18, 2010Software engineer at makandra GmbH

This is non-trivial because you need to fake event objects and require different code for different browsers. Luckily, there is tool support for most types of events.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

In jQuery you can say:

$('a#close_window').click();

In Prototype you can use event.simulate.js Show archive.org snapshot from the Protolicious library to say:

$$('a#close_window')[0].simulate('click');

To trigger custom events with Prototype, you can use the built-in Element.fire() Show archive.org snapshot function. In Prototype, custom events MUST be namespaced.

this.fire('custom:event');
Posted by Henning Koch to makandra dev (2010-11-18 18:17)