Skip to content Skip to sidebar Skip to footer

Catch Javascript Customevent By Jquery On() Preserving Custom Properties At First "level"

I have a setup theoretically like this [see fiddle -> http://jsfiddle.net/GeZyw/] : var EventTest = function(element) { this.element = element; this.element.addEventList

Solution 1:

I have run into the same issue, couple of months ago, the point is:

When an event is received by jQuery, it normalizes the event properties before it dispatches the event to registered event handlers.

and also:

Event handlers won't be receiving the original event. Instead they are getting a new jQuery.Event object with properties copied from the raw HTML event.

Why jQuery does that:

because it can't set properties on a raw HTML event.

I had decided to do the same, I started to do it with a nasty way, and my code ended up so messy, at the end I decided to use jQuery.trigger solution, and pass my event object as the second param, like:

$("#test").bind("myevent", function(e, myeventobj) { 
    alert(myeventobj.xyz);
});
var myobj = {"xyz":"abc"};
$("#test").trigger("myevent", myobj);

for more info check this link out: .trigger()

Post a Comment for "Catch Javascript Customevent By Jquery On() Preserving Custom Properties At First "level""