开发者

JQUERY How do I fadeout on post success?

开发者 https://www.devze.com 2023-02-02 16:26 出处:网络
I want to fade out开发者_如何学运维 my div once the button inside it is clicked, and the resulting post request returns successful.

I want to fade out开发者_如何学运维 my div once the button inside it is clicked, and the resulting post request returns successful.

$('.btn').click(function(){
            var u_id = $(this).attr('id');
            $.post("actdeact.php",{do_action:'activate',uid:u_id},function(data){
                $(this).fadeOut("500");
                alert('loaded '+data);
            });
        });

since the divs are dynamically generated I used a class instead of an id (or each()). But it seems I cannot use $this for the fadeout.....any ideas?


Try this:

$('.btn').click(function(){
            var that=$(this);
            var u_id = $(this).attr('id');
            $.post("actdeact.php",{do_action:'activate',uid:u_id},function(data){
                that.fadeOut("500");
                alert('loaded '+data);
            });
        });

The idea is to get the reference to $(this) before calling $.post

0

精彩评论

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