+ 1
Js buttons
I have button in my code it run a function but when you clicked more than once it run again and again How to prevent that
3 odpowiedzi
+ 5
you can also add a {once:true}.
const btn = document.getElementById("btn");
btn.addEventListener("click",handleClick, {once:true});
function handleClick() {
console.log("btn clicked");
}
+ 3
You can remove event listener inside this function:
https://code.sololearn.com/Wqfi62H89Plx/?ref=app
+ 2
You can put the condition in your function, like: initialize a variable with true and put a if condition inside your function and at the end of the function reassign the same variable to false.