I'm trying to set up a page with several buttons, all of which toggle from red to green when a task is completed. However, I want them to be able to toggle back if a mistake is made. So far, I have the following function:
<button id="button">button</button>
<script>
function changeColor(button) {
var thisButton = document.getElementById(button)
if (thisButton.style.background == '#0f0') {
thisButton.style.background='#0f0';
} else {
thisButton.style.background='#f00';
}
}
</script>
If I use 'red' or 'green' as the colours, this works, but if I use hex as above, or rgb (255,0,0), the if always returns 'false'. Any ideas what I'm doing wrong?