I'm trying to change the background color of a element when it is clicked on. Basically, I want to be able to toggle this color back and forth each time it's clicked.
Here's the code I'm using:
function activateButton1() {
var x = document.getElementById('postButton1');
if (x.className == 'postButton1') {
x.className = 'postButton1on';
} else {
x.className = 'postButton1';
}
}
I'm using two different CSS classes that have different background colors, but it's not working. Can anyone offer any insight?