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/
4 odpowiedzi
+ 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
}
});
+ 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() {
});
+ 1
Ok guys, really sorry. I've just erased the onclick function in javascript file (within the switch case 1 ). Thank you to all.
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)