使用关闭按钮添加DIV,使用Jquery动态添加到另一个DIV [英] Adding DIV with a close button, dynamically to another DIV using Jquery

查看:189
本文介绍了使用关闭按钮添加DIV,使用Jquery动态添加到另一个DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加4个div,这些div的右上角带有关闭按钮,并与父DIV水平对齐. 单击关闭按钮后,应从父DIV中删除div.如果有人可以发布示例代码,那么Jquery可以实现吗?

I would like to add 4 divs with close buttons on top right corner , aligned horizontally to a parent DIV. When the close button is clicked, the div should be removed from the parent DIV. Is this possible with Jquery ?if someone could post a sample code i would really appreciate it !

谢谢

推荐答案

让我们为您提供帮助.

jsBin演示

<div class="box">
    <div class="close_box">X</div>

    <h2>Box title</h2>
    <p>Merol muspi rolod tis tema...</p>

</div>

jQ:

$(document).on('click','.close_box',function(){
    $(this).parent().fadeTo(300,0,function(){
          $(this).remove();
    });
});

或简单地:

$(document).on('click','.close_box',function(){
    $(this).parent().remove();
});

看看文档(总是!):

http://api.jquery.com/on/
http://api.jquery.com/parent/
http://api.jquery.com/remove

http://api.jquery.com/on/
http://api.jquery.com/parent/
http://api.jquery.com/remove

这篇关于使用关闭按钮添加DIV,使用Jquery动态添加到另一个DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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