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?

2
  • Why are you using both libraries? And why can't you just trigger the event from Prototype? Commented Aug 25, 2009 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 Commented Aug 27, 2009 at 13:52

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.