Cycle through div background colors onClick with Javascript
<p>I'm trying to change a div background color to a different color depending on what the div's current color is, when the div is clicked on. The following code does not work. I've figured it has something to do with my "if" statements because it works fine if I just make them change to 1 color with no "if" statements.</p>

<pre><code>&lt;script language="JavaScript"&gt;
function setColor(blockId) {
    if (document.getElementById(blockId).style.background == '#FF0000') {
        document.getElementById(blockId).style.background = '#0000FF';
    }else if (document.getElementById(blockId).style.background == '#0000FF') {
        document.getElementById(blockId).style.background = '#999999';
    }else if (document.getElementById(blockId).style.background == '#999999') {
        document.getElementById(blockId).style.background = '#FF0000';
    }
}
&lt;/script&gt;

&lt;div id="b1" style="background-color:#FF0000; height:100px; width:100px;" onClick="setColor('b1')"&gt;&lt;/div&gt;
</code></pre>
