It seems .on()
failed to bind newly created element from clone()
<div class="container">
<div class="add">add</div>
</div>
$(".remove").on("click",function() {
$(this).remove();
});
$(".add").on("click", function() {
$(this).clone().toggleClass("add remove").text("remove").appendTo($(".container"));
});
Why this doesn't work?
Update:
please note that, I know .clone()
takes two parameters, but I don't want to let the cloned element continue registered to the old events, but a new one, I could use .off()
and .on()
to register again, but my question is why the previously declared .on(".remvove")
didn't capture the change in the cloned element.