[Solved] Q. Is it possible to make a function run only once. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

[Solved] Q. Is it possible to make a function run only once.

I have a canvas. A function starts running upon clicking the canvas. I want that the canvas screen is only clickable once. Or making the function not interuppt other functions.

1st Dec 2021, 2:54 PM
Shobhit :)
Shobhit :) - avatar
5 Answers
+ 4
Shobhit :) U can use addEventListener (Third argument) HTMLElement. addEventListenter('click', ()=>{ //some function }, {once:true}) example https://code.sololearn.com/WlP82QNb0zMH/?ref=app
1st Dec 2021, 4:41 PM
Pariket Thakur
Pariket Thakur - avatar
+ 5
You could remove the click event after the click
1st Dec 2021, 3:13 PM
Lisa
Lisa - avatar
+ 4
2nd Dec 2021, 5:16 AM
Shobhit :)
Shobhit :) - avatar
1st Dec 2021, 3:22 PM
Sancho Godinho
Sancho Godinho - avatar
+ 2
Shobhit :) There is one() method in jQuery which allow you to click only once.
1st Dec 2021, 4:26 PM
A͢J
A͢J - avatar