I am creating some a tag dynamically. Then I am trying to attach click event with them. But those events are not firing.
Here is my code:
$(function() {
onUploadReady();
});
var onUploadReady = function() {
$('a[name=add]').on('click', function(event){
event.stopPropagation();
$('table#multiUpload').append('<tr><td style=\"text-align: center;\"><input type=\"file\" name=\"file\"/></td><td><a href="#" name="remove">Remove</a></td></tr>');
return false;
});
$('a[name=remove]').on('click', function(event){
event.stopPropagation();
$(this).parents('tr').eq(0).remove();
return false;
});
}
If I do $('a[name=remove]').live('click', function(event)
instead of $('a[name=remove]').on('click', function(event)
, then the event is firing. I read somewhere that usage of live
is discouraged, and we should use on
. Also event propagation or bubbling can occur if we use live
. So how do I solve the issue?