I'm trying to have jQuery listen to an event that is not triggered by jQuery.
Here is the listener:
$(document).on("end.eTime", function (e) {
console.log("here");
$("body").append(e.name + " " + e.ellapsed + "<br>");
});
Here is the trigger:
var event= new CustomEvent('end.eTime', {custom: object})
document.dispatchEvent(event);
Using newest firefox to test.
If I trigger using jQuery's trigger it works fine, but I'm trying to write a pure js library.
If I try to listen with a native listener it works fine, but I would like to allow users of my library to use jQuery.
Can anyone tell me why jQuery $.on() doesnt want to listen to a native custom event?
Update
So I removed the namespace as @Derek suggested and then jquery will listen for it correctly. I believe this is a bug so I submitted it here:http://bugs.jquery.com/ticket/15143.
I also found, as expected, that native listeners cannot hear jquery events. As @kcent said, they use a completely different process, so its no wonder it doesnt work. The documentation says that it still calls the native events, but this is probably only for things like click. This doesnt effect me for this process, but I still mention in the ticket that it would be nice if it worked.
For a whole series of examples you can check the ticket on jquery.
.on()
call; is there any reason you need to use a.
in the event name?"."
in the event name (which I'm sure jQuery doesn't already have the ability to do)