Stop function javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Stop function javascript

I would like to stop function if user click on a button. I know there is 'return' but it does nothing... function abc () { $('.stop').click (function () { return; }); } $('.start').click (function() { abc (); }); example : how to stop the abc function after the user click to .start and decided to click to .stop ?

21st Oct 2017, 10:11 AM
NoxFly
NoxFly - avatar
4 Answers
+ 5
Use jquery .on() and .off() functions to add or remove an event handler.
21st Oct 2017, 11:14 AM
Calviղ
Calviղ - avatar
+ 5
Unless abc is in a setInterval function, it should be pointless to stop a function which would take a fraction of second to be executed
21st Oct 2017, 10:19 AM
Dapper Mink
Dapper Mink - avatar
+ 4
en fait t'as un menu, si tu click sur -easy : ça fait cette fonction. une fois la game terminée ça te demande 'restart' ou 'menu' si tu reviens dans menu et que cette fois tu choisis 'medium', ça executera pas la même fonction. mais ça continue à exexuter la fonction 'easy'... faut que je fasse UNE seule fonction avec un Switch {} dedans ?
21st Oct 2017, 10:27 AM
NoxFly
NoxFly - avatar
+ 4
Pas obligatoirement Tu peux changer la difficulté avec seulement des variables par exemple Mais pour stopper la fonction j'aurais besoin d'en savoir plus sur la structure de ton code désolé
21st Oct 2017, 10:34 AM
Dapper Mink
Dapper Mink - avatar