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

前端 未结 2 921
失恋的感觉
失恋的感觉 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:35

    Replace

    this.hide(); 
    

    with

    $(this).hide();
    

    Thus your function should be like

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

    See the official documentation here

提交回复
热议问题