简体   繁体   English

手风琴点击删除Div

[英]Accordion Remove Div on click

I have this accordion 我有这个手风琴

<div id="accordion" class="accord">
    <h2>
        <a href="#">Item1</a></h2>

    <div>
        Content1
    </div>
    <h2 >
        <a href="#">Item2</a></h2>
    <div>
       Content#2
    </div>
</div>

    $("#accordion").accordion({
        autoHeight: false,
        animated: 'bounceslide',
        icons: { "header": "ui-icon-plus", "headerSelected": "ui-icon-minus" }
    });

i would like to add a link on each Item that will remove that Acoordion Div, how do i do so? 我想在将删除该Acoordion Div的每个项目上添加一个链接,我该怎么做?

(function ($) {        $("#accordion").children("div").each(function(index, element) {
$(element).append('<div class="delete">x</div>');
$(element).children('.delete').bind('click', function() {
$(element).hide();
});
});
}(jQuery));

I see you don't have any link to remove the DIV section. 我看到您没有任何链接可删除DIV部分。

Assuming that you have it, here is my sample. 假设您有,这是我的示例。

$('.remove').click(function(e) {
    $(this).parent('div').prev('h2').andSelf().remove();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM