Thursday 5 July 2012

click event not working for anchor tags added dynamically

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

No comments:

Post a Comment