guttyguppy
Programmer
Hi, first post here!
I'm doing an art project and having trouble. I want a div's background color to turn black if it's white, and white if it's black. Here's my code:
The box turns black, but doesn't return to white when it's clicked again. What am I doing wrong? Thanks for any advice.
I'm doing an art project and having trouble. I want a div's background color to turn black if it's white, and white if it's black. Here's my code:
Code:
function toggle(obj) {
var el = document.getElementById(obj);
el.style.backgroundColor = (el.style.backgroundColor != 'rgb(0,0,0)' ? 'rgb(0,0,0)' : 'rgb(255,255,255)' );
}
<div id="a8" onClick="toggle('a8');"></div>