+ 19

[SOLVED] Toggle effect

I want to change the background color each time I click on the box. How can I do that? I've been trying to do that with if statement but it didn't work. Here's the code https://code.sololearn.com/W5QHMMczGPw4/?ref=app

3rd Feb 2019, 12:55 AM
voja
voja - avatar
2 Respuestas
+ 12
Add the following code in script tag: function myfunc(){ document.getElementsByTagName("body")[0].classList.toggle("change"); } Add a class in css .change { background-color: aqua; }
3rd Feb 2019, 2:07 AM
Random
Random - avatar
+ 14
It works!!! 👌👏👏 Thanks a lot Ankit 😃👍
3rd Feb 2019, 2:13 AM
voja
voja - avatar