Is it possible to handle double clicks with one click in Javascript?

I am learning Javascript. I noticed that if I click on an object several times, quickly, some clicks are captured as double clicks. Is it possible to capture all clicks in Javascript in just one click?

thank

+3
source share
2 answers

Using jQuery, you can create a double-click event handler in a document, and then prevent this default behavior:

$(document).dblclick(function(e) {
    e.preventDefault();
    alert('Handler for .dblclick() called and ignored.');
});

Double-click in the example to see the result.

+2
source

There are two options for solving this problem.

1) Using "return false"; double click event expression. Example:

<button id="your button id" onclick="yourfuntion()" ondblclick="return false;" >My Button</button>

2) / .

:

<button id="your button id" onclick="yourfuntion()">My Button</button>

<script>

function yourfuntion() { document.getElementById("your button id").disabled = true; 
//your javascript code 

document.getElementById("your button id").disabled = false;}

</script>
0

Source: https://habr.com/ru/post/1757333/


All Articles