W
W
Worddoc2017-09-07 15:32:38
JavaScript
Worddoc, 2017-09-07 15:32:38

javascript. How to disable a click on an element for a certain time after clicking on it?

Hello. Take, for example, a hamburger menu. How to avoid fast(=ugly) toggle menu state by disable click AFTER click for a certain amount of time? It only comes to mind to give/remove the css property pointer-events, or write true/false to a variable, and on click check whether the variable is true and click accordingly. But I feel that this is not the most elegant solution. Tell your friends, but it would be generally cool if there was a code example. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kornilov, 2017-09-07
@KorniloFF

<button onclick="this.disabled=1; setTimeout((function(){this.disabled=0}).bind(this),2000)">Click</button>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question