jQuery click() still being triggered after .clickable class is removed

后端 未结 7 805
时光说笑
时光说笑 2020-12-03 05:29

I\'ve got a click event assigned to a div of a particular class. When the click occurs, the class is removed from the div. However, you can still click the div and the

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 05:38

    If you want to call click event only once use jQuery one function to bind events it will destroy itself.

    $('.clickable').one('click',function() {
       $(this).removeClass('clickable');//remove the class
       $(this).addClass('not-clickable');
       alert('Clicked!');
    });
    

提交回复
热议问题