Let's say I have those divs with some code in the same document:
<div id="trigger">Click Me!</div>
<div id="handler">Handler</div>
<script type="text/javascript">
$("#handler").on('check', function() {alert('Handler is working!');})
$("#trigger").on('click', function()
{$("#handler").trigger('check');alert('Trigger is working!')
})
</script>
It's working as expected.
However, if I use .load()
to inject all this into a page, then only the (native) trigger event, not the (custom) handler event is working.
I guess it has something to do with timing but I thought .on()
was supposed to take care of timing issues?
EDIT: THE SOLUTION
I got it all wrong. I wasn't aware that a document loaded simultaneously with the above had its own reference to the Jquery source. So a different version of Jquery was loaded on top of the one already in the DOM. Now it's working without .ready()
and even with the original syntax.
Thanx!