I\'m attempting to write a video poker game in Javascript as a way of getting the basics of it down, and I\'ve run into a problem where the jQuery click event handlers are f
The below code worked for me in my chat application to handle multiple mouse click triggering events more than once.
if (!e.originalEvent.detail || e.originalEvent.detail == 1)
{ // Your code logic }
We must to stopPropagation()
In order to avoid Clicks triggers event too many times.
$(this).find('#cameraImageView').on('click', function(evt) {
evt.stopPropagation();
console.log("Camera click event.");
});
It Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. This method does not accept any arguments.
We can use event.isPropagationStopped()
to determine if this method was ever called (on that event object).
This method works for custom events triggered with trigger(), as well.Note that this will not prevent other handlers on the same element from running.
$(element).click(function (e)
{
if(e.timeStamp !== 0) // This will prevent event triggering more then once
{
//do your stuff
}
}
.one only fires once for the lifetime of the page
So in case you want to do validation, this is not the right solution, because when you do not leave the page after validation, you never come back. Better to use
$(".bet").on('click',function()
{ //validation
if (validated) {
$(".bet").off('click'); //prevent to fire again when we are not yet off the page
//go somewhere
}
});
It happens due to the particular event is bound multiple times to the same element.
The solution which worked for me is:
Kill all the events attached using .die()
method.
And then attach your method listener.
Thus,
$('.arrow').click(function() {
// FUNCTION BODY HERE
}
should be:
$('.arrow').die("click")
$('.arrow').click(function() {
// FUNCTION BODY HERE
}
Try that way:
<a href="javascript:void(0)" onclick="this.onclick = false; fireThisFunctionOnlyOnce()"> Fire function </a>