0

Reiteration onclick event on same element with different functions don't execute

Hello guys, How can i reiterate the onclick event in this exercise?it run only once and then the code is computed but without the animation (see the "console.log(flag)"). I've tried many solution (onclick javascript, use of flag, jquery toggle(), switch case, if else statement) but it won't work. Where am i wrong? https://code.sololearn.com/WzYuT90i7OqH/

5th Jan 2019, 3:03 PM
Simone
Simone - avatar
4 ответов
+ 3
Additional to Toni Isotalo's answer, You can also toggle between 2 functions with 1 onclick, in this case it would show and hide the content instead of creating and deleting content.👍 // Set value to toggle between content var flag=0; $("#display").on("click",()=>{ // Hide the content if value is 1 which equals false if(flag==1){ flag=false; // Code here } // Show content if the value is 0 which equals true else { flag=true; // Code here } });
5th Jan 2019, 3:28 PM
🌴Vincent Berger🌴
🌴Vincent Berger🌴 - avatar
+ 2
I’m not sure but it seems that you keep adding the onclick event over and over again. It doesn’t overwrite the old one. Try to delete the old event before creating a new one. $(“#” + letter).off().on(“click”, function() { });
5th Jan 2019, 3:20 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
Ok guys, really sorry. I've just erased the onclick function in javascript file (within the switch case 1 ). Thank you to all.
5th Jan 2019, 4:33 PM
Simone
Simone - avatar
0
i've tried just few minutes ago. it' didn't work. If you notice, after the first time, the function is done without pauses (as opposed to what happens at the first click)
5th Jan 2019, 3:28 PM
Simone
Simone - avatar