Possible Duplicate:
Jquery adding event listeners to dynamically added elements
jQuery bit:
I append an input field with some text to a div:
shareVisual = '<div class="individual-share">' + '<input type="number" value="1" /> X ' + classname.val() + '@' + classcurrency.val() + ' ' + classprice.val() + ' per share ' + '<button type="button" class="remove-share">Remove</button></div>';
listOfSharesBox.append(shareVisual);
And then i try to catch an on-click event:
$("#list-of-shares").bind('click', '.remove-share', function() {
$(".remove-share").closest("div").find(".individual-share").remove();
});
Why does the DIV not get removed?
Cheers.
P.S.
when i change my code to this:
$("#list-of-shares").bind('click', '.remove-share', function() {
$(".remove-share").closest("div").remove();
});
All of the dynamically generated inputs get deleted within the div.