I'm trying to utilize jQuery's custom events. On DOM load I bind body
to a custom event test
using $.on()
. Immediately after, I fire that event and everything runs as planned. However, any other time I fire the event (on a callback, from the console, etc.), nothing happens. I've written a jsfiddle to illustrate this situation. Any ideas?
$(function(){
$('body').on('test', function(){
alert('test triggered');
});
$('body').on('click', '.btn', triggerTest);
$('body').trigger('test');
});
var triggerTest = function(){
$('body').trigger('test');
}