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

后端 未结 7 654
时光说笑
时光说笑 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:48

    Your understand of even assignment is a bit wrong. Please read your code

    $('.clickable').click(function()
    
    1. Find element with the class '.clickable'
    2. Assign onclick handler to the element

    See, it's the element that get's handler, not the class name. You need to remove the handler. For that you can try:

    $('.clickable').click(function() {
        $(this).removeClass('clickable');
        $(this).addClass('not-clickable');
        alert('Clicked!');
        $(this).unbind('click');
    });
    
    0 讨论(0)
提交回复
热议问题