jQuery methods not working on 'this' inside an event handler

前端 未结 2 961
失恋的感觉
失恋的感觉 2021-01-21 11:37

When I use the below, I cannot get the jQuery this to hide the element.

$(\'.purplePanda\').click(function(e){
   this.hide();
});

2条回答
  •  自闭症患者
    2021-01-21 12:28

    Modify your code from that :

    $('.purplePanda').click(function(e){
       this.hide();
    });
    

    To This:

    $('.purplePanda').click(function(e){
       $(this).hide();
    });
    

    Should work now.

提交回复
热议问题