开发者

Detecting closest or parent div

开发者 https://www.devze.com 2023-02-10 06:21 出处:网络
I have the following script: http://jsfiddle.net/开发者_如何学运维oshirowanen/pALBV/ How do I make this more dynamic, so I do not have to manually specify the button clicks for each button if the nu

I have the following script:

http://jsfiddle.net/开发者_如何学运维oshirowanen/pALBV/

How do I make this more dynamic, so I do not have to manually specify the button clicks for each button if the number of buttons on screens is unknown as in the end result, the containers along with the container content will be database generated.

At the moment, I have only specified button_2 in jquery script.


try this:

$(function() {
    $(':button').click(function() {
        $(this).closest('.container').fadeOut('slow', function() {
            $(this).remove();
        });
    });
});


This works:

$(function() {
    $('input[type="button"]').click(function() {
        var container = $(this).parent().parent();
        container.fadeOut('slow', function() {
            container.remove();
        });
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消