Lets say you are inserting new elements to the DOM and trying to add the onclick event to it, it wont work with just .click function. For that below is the solution.
$('#add').live('click', function(e) {
e.preventDefault();
alert('hello');
});
Reference:http://stackoverflow.com/questions/2264246/jquery-click-event-of-a-tag-added-at-run-time-doesnt-get-fired
$('#add').live('click', function(e) {
e.preventDefault();
alert('hello');
});
Reference:http://stackoverflow.com/questions/2264246/jquery-click-event-of-a-tag-added-at-run-time-doesnt-get-fired
No comments:
Post a Comment