如何从div中删除项目? [英] How can I remove items from div?

查看:98
本文介绍了如何从div中删除项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究MVC5项目,在那里我动态创建html。



使用jquery,



I am working on MVC5 Project, there I am dynamically creating html.

Using jquery,

$("#divbindProjectlist").append('<a href="#" class="list-group-item projectList" ><span class="project-name">' + json.ProjectName + '<input type="hidden" value="' + json.idPartnerProject + '" /></span><i class="pull-right close-p">x</i></a>');





查看,





View,

<div id="divbindProjectlist" class="left-top-p">
    <a class="list-group-item active left-menu-head">Projects List</a>
    <a href="#" class="list-group-item projectList">
        <span class="project-name">ssssssss</span><i class="pull-right close-p">x</i>
        <input type="hidden" class="hidprojectId" value="0.37421775864182916">
    </a>
    <a href="#" class="list-group-item projectList">
        <span class="project-name">asdfasdf</span><i class="pull-right close-p">x</i>
        <input type="hidden" class="hidprojectId" value="0.6032844290071158">
    </a>
    <a href="#" class="list-group-item projectList">
        <span class="project-name">asdfasdf</span><i class="pull-right close-p">x</i>
        <input type="hidden" class="hidprojectId" value="0.28981124419382853">
    </a>
</div>





我尝试了什么:



现在,如何在cl时删除每个'a'元素ick on x?



我试过这个。但是没有工作。





What I have tried:

Now, How can I remove the each 'a' element when click on x ?

I have tried this. But not working.

$(document).on("click", ".close-p", function () {
       $(this).parentsUntil(".list-group-item.projectList").remove();
   });

推荐答案

#divbindProjectlist)。append(' < a href =#class = list-group-item projectList>< span class =project-name>' + json.ProjectName + ' < input type =hiddenvalue =' + json.idPartnerProject + ' />< / span>< i class =pull-right close-p> x< / i>< / a>');
("#divbindProjectlist").append('<a href="#" class="list-group-item projectList" ><span class="project-name">' + json.ProjectName + '<input type="hidden" value="' + json.idPartnerProject + '" /></span><i class="pull-right close-p">x</i></a>');





查看,





View,

<div id="divbindProjectlist" class="left-top-p">
    <a class="list-group-item active left-menu-head">Projects List</a>
    <a href="#" class="list-group-item projectList">
        <span class="project-name">ssssssss</span><i class="pull-right close-p">x</i>
        <input type="hidden" class="hidprojectId" value="0.37421775864182916">
    </a>
    <a href="#" class="list-group-item projectList">
        <span class="project-name">asdfasdf</span><i class="pull-right close-p">x</i>
        <input type="hidden" class="hidprojectId" value="0.6032844290071158">
    </a>
    <a href="#" class="list-group-item projectList">
        <span class="project-name">asdfasdf</span><i class="pull-right close-p">x</i>
        <input type="hidden" class="hidprojectId" value="0.28981124419382853">
    </a>
</div>





我的尝试:



现在,如何在点击x时删除每个'a'元素?



我试过这个。但不工作。





What I have tried:

Now, How can I remove the each 'a' element when click on x ?

I have tried this. But not working.


文档)。on( click .close -p function (){
(document).on("click", ".close-p", function () {


this )。parentsuntil( .list-group-item.projectList)。remove();
});
(this).parentsUntil(".list-group-item.projectList").remove(); });


这篇关于如何从div中删除项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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