4

I have a Prototype code that is triggered upon 'load' event:

  Event.observe($(imageEl), 'load', this.someFunction.bind(this));

When I create 'Real' event using jQuery code like

  jQuery(...imageEl selector...).attr("src", filename);

it fires the Prototype code (someFunction). Good!

Next I try to fire the Prototype code using jQuery trigger:

  jQuery(...imageEl selector...).trigger('load');

But now, nothing happen i.e. this line doesn't fire the Prototype code.

Any idea how to trigger a Prototype event from jQuery?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Why are you using both libraries? And why can't you just trigger the event from Prototype? – James Aug 25 '09 at 23:54
  • Of course if I would write my code from scratch I would only use jQuery. Unfortunately I have to integrate an old code based on Prototype + Scriptaculous with new code based on jQuery. Both codes reacts to external events! Specifically, jQuery/UI "resizable" changes the size of DOM object(s) whose children are managed by the old Scriptaculous-based code for zooming (using Scriptaculous slider etc.). I kind of solved the problem using the DOMAttrModified event. I use this in jQuery: jQuery(...).attr({...}); to trigger this: Event.observe(..., 'DOMAttrModified', ... ); Cheers, Sty –  Aug 27 '09 at 13:52

1 Answers1

2

You should call your handler directly passing required arguments or trigger the native DOM event.

NOTE: prototype's fire and jquery's trigger create custom events, not native.

Read the following answers on how to trigger native events:

Community
  • 1
  • 1
Sergiy Sokolenko
  • 5,967
  • 35
  • 37