I have created a button that changes the background color to gradient and when I double click it, it returns back. When I click the button, it changes the color and text(hello) of itself to gradient and text(hi), but when I double click it, the button doesn’t return back, it just shows the gradient and text(hi). I tried the codes answered to the question ‘toggle button background color when clicked’ they are also not working. Can you help me to solve this problem?
I tried some javascript code, that I found in stack overflow. But it is not working.
function myFunction() {
document.body.style.background = "linear-gradient(orange, white, green)";
}
function myFunction2() {
document.body.style.background = "#22232e";
}
<button onclick="myFunction()" ondblclick="myFunction2()">
<span>hello</span>
<span>hi</span>
</button>
2
Answers
You can achive this using css transition property.If you want it change it’s background color countinuously then you can try keyframes animation.And for click event you can use ‘:focus’ pseudo-class.For example——
css property
Or you can use keyframes animation.It will change background color infinite loop after click on the button. For example—
//here`s the js