删除动态当前元素 [英] Remove dynamic current element

查看:72
本文介绍了删除动态当前元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有形式和添加按钮底部的te形式这是正确的。每当点击它的添加新的表单与删除按钮,如果我点击它必须删除当前表单


$ b $($。$ iade_sil)。on(click,function(){$ b $ p $ my $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'
$(this).parents(。add_after)。find(。group)。remove();
});

如果您想要,您可以看到完整的演示版和js文件

codepen演示

解决方案

您必须注册侦听器才能观看所有新元素。并且您希望使用最接近,而不是父母



即使你也不需要最接近,你可以直接选择 .group ,因为你的删除按钮在里面元素:

  $(document).on(click,.iade_sil,function(){
$(this).closest(。group)。remove();
});


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 code

$(".iade_sil").on("click",function(){
        $(this).parents(".add_after").find(".group").remove(); 
    });

and if you want you can see full demo and js files

codepen demo

解决方案

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(); 
});

这篇关于删除动态当前元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆