开发者

Detecting closest or parent div

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜