Detecting closest or parent div

后端 未结 2 1002
醉梦人生
醉梦人生 2021-01-16 19:19

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 f

相关标签:
2条回答
  • 2021-01-16 19:26

    try this:

    $(function() {
        $(':button').click(function() {
            $(this).closest('.container').fadeOut('slow', function() {
                $(this).remove();
            });
        });
    });
    
    0 讨论(0)
  • 2021-01-16 19:51

    This works:

    $(function() {
        $('input[type="button"]').click(function() {
            var container = $(this).parent().parent();
            container.fadeOut('slow', function() {
                container.remove();
            });
        });
    });
    
    0 讨论(0)
提交回复
热议问题