Allow just one click in class JQUERY

后端 未结 2 482
日久生厌
日久生厌 2020-12-12 01:03

I have a link that will load via ajax some content.

My problem is, I don\'t want to remove the text \"Load comments\", I just want to not allow more clicks in this c

相关标签:
2条回答
  • 2020-12-12 01:45

    Use jQuery's one() function

    $(".showcomments").one("click", function() {
    

    http://www.w3schools.com/jquery/event_one.asp

    The one() method attaches one or more event handlers for the selected elements, and specifies a function to run when the event occurs.

    When using the one() method, the event handler function is only run ONCE for each element.

    0 讨论(0)
  • 2020-12-12 02:01

    When you bind an event handler, you bind to the element, not to the class. Removing a class from an element doesn't change which event handlers are bound to the element.

    You could use off() to remove the event handler:

    $(this).off('click');

    http://jsfiddle.net/om6ggvyu/

    0 讨论(0)
提交回复
热议问题