I created a sample case:
$(function(){
function ping (){
alert( "function fired" );
console.log("fired");
}
console.log($("input#one")[0]);
$("input#one")[0].addEventListener("change", ping);
$("input#one").trigger("change");
$("input#two").on("change", ping);
$("input#two").trigger("change");
});
It seems that with jQuery, you cant "trigger" and event applied with the addEventListener
call. Is there a reason for this? I was under the notion that since trigger is a jquery method, it is only scanning the jQuery object for the handlers, and not what is actually applied to the object.
I feel that trigger should fire for all applicable events, whether they were added via on
or addEventListener
. Maybe it is taking a snapshot of code at timeframe X, and is storing it in the jquery object. Im not sure.
Maybe someone else has more insight into this than myself?