I have black text that when double clicked, changes to a different color. I want it to be able to change back to black on a double click. Right now, I have:
<script>
<h1 id="color"> I CHANGE COLORS! </h1>
<a href="javascript:void(0)" ondblclick="
counter++;
if(counter%2==1){color()} else {black()}
">Double click here</a>
</script>
The two functions called are color() and black(). Is there anyway I can use a toggle instead of this if-else with javascript?
Store the functions in a globally accessible object:
And then invert your state flag:
While this satisfies your very arbitrary requirements, it’s a hideous solution.