jQuery trigger not firing with bind() or on() for custom events -
can tell me why code not working?
$('body').on('test', function() { alert('test'); }); $('body').trigger('test'); i'm using jquery-1.7.2.min. not errors, nothing happens.
i've tried putting code inside inline script, inside $(document).ready() , still nothing. i've tried both on() , bind() , neither result. see examples on showing same syntax, different this?
it appears issue lies in dom being ready somehow. placing code within inline script not work. placing inside of $('document').ready() work anonymous function, reason not function call '( )'.. code worked
$(document).ready(start); function start(){ $('body').on('test', function() { alert('test'); }); $('body').trigger('test'); } but did not... *notice function call parenthesis.
$(document).ready(start()); function start(){ $('body').on('test', function() { alert('test'); }); $('body').trigger('test'); } an exact example works both ways on jsfiddle, reason 1 way works on server. guess bring question of why, @ least can see code in fact work, there strange anomaly stuff :/
Comments
Post a Comment