Is it intentionally so that using $('#foo').trigger('keyup') or the
shorthand $('#foo').keyup() will not propagate as with a real keyup event?
Same goes for clicks and others too.
To take full advantage of event bubbling / delegation I have made attached
most event listeners to the body element. This greatly boosts performance on
pages that would otherwise require lots of individual similar listeners.
Another obvious advantage is that the listeners are automatically usable for
any new elements generated dynamically / loaded with Ajax. I would like to
fire some of those events from the code though, but using trigger() or
keyup() on the elements does not propagate up to the body element, as I
would have hoped, and therefore the function never fires on the body event
listener.
Simplified example:
Upon loading the script fires the click-event on #foo. This will not
propagate to the event listener at body. Manually clicking the div, however,
works.
html code:
-----------
<body>
<div id="foo">Lorem ipsum dolor</div>
</body>
Javascript:
----------
$(document).ready(
function()
{
$('body').click(function(event){
alert($(event.target).id() + ' was clicked!');
});
$('#foo').click();
}
);
Is there a way to force the propagation, or is there any other way to
simulate events such as keyup and click from the code?
--
Suni
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/