I have an Raphael element with click event handler:
var paper = Raphael("container", 770, 160);
var c = paper.rect(10, 10, 50, 50);
c.click(function () {
alert("triggering");
})
How I can manually fire this event? (c.click() don’t work)
Thanks!
Although this question is already answered, I will post my solution which I found out by random.
It’s possible with the Raphael internals:
When you attach an event listener like
element.click(func)then theelementobject holds an array with all events. In this array there’s an object which has a methodf(strange naming convention) which triggers the event.So to sum it up you can call your event with knowing the order of your events, in your case there’s just the
clickevent which is on index 0, you can call it like:c.events[0].f();A more generic solution would be a function like
But beware that if you had multiple
clickevents all were triggered.Here’s a fiddle to demonstrate.