Skip to content
Advertisement

How can I repeatedly change the background style of a div using a click event in Javascript?

I am trying to change the background property of each day on a calendar, when clicked, between blue and green using javascript and CSS. like a toggle function. The default color is blue, and I’ve managed to get each day to turn green when clicked but I can’t figure out how to change them back to blue.

Here’s what I’ve tried.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

Define a CSS class that has the style for green background color and using javascript, just toggle that class on each div element.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement