jQuery click events firing multiple times
To make sure a click only actions once use this:
$(".bet").unbind().click(function() { //Stuff});
.unbind()
is deprecated and you should use the .off()
method instead. Simply call .off()
right before you call .on()
.
This will remove all event handlers:
$(element).off().on('click', function() { // function body});
To only remove registered 'click' event handlers:
$(element).off('click').on('click', function() { // function body});
.one()
A better option would be .one()
:
The handler is executed at most once per element per event type.
$(".bet").one('click',function() { //Your function});
In case of multiple classes and each class needs to be clicked once,
$(".bet").on('click',function() { //Your function $(this).off('click'); //or $(this).unbind()});