Remove Dynamic Current Element
I have form and Add button bottom of te form which is the right..and whenever click it's adding new a form with delete button and if I click it has to delete current form my js co
Solution 1:
You have to register the listener to watch all new elements too. And you want to use closest
, not parents
.
Even you dont need the closest
too, you can select the .group
directly, because your delete button is inside that element:
$(document).on("click", ".iade_sil", function() {
$(this).closest(".group").remove();
});
Solution 2:
Also you can use closest to that gorup class
$(document).on("click", ".iade_sil", function() {
$(this).closest(".group").remove();
});
Solution 3:
You need to use event delegation for attaching events to dynamically added DOM. You should also use .closest()
instead of .parents()
and traverse to group element:
$(document).on("click",".iade_sil",function(){
$(this).closest(".group").remove();
});
Post a Comment for "Remove Dynamic Current Element"