Why this code works (see code at jsfiddle)
$(document).ready(function() {
var html = '<div><a href="javascript:">click me</a></div>';
var $div = $(html);
$div.find('a').bind('click', function() { //attention on bind
alert('Hi');
});
$('#test').append($div);
});
but the same code with .bind('click'
replaced with .live('click'
is not working? Why?
Thank you.
jQuery documentation says:
DOM traversal methods are not supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector.
So if you change $div.find('a').bind('click'
to $('#test a').live('click'
it would work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With