Changing a menu tab's color on click
I would suggest changing your html and giving all the tags some class like 'tag', then you'll be able to do something like:

&lt;button id="tab1" class="tab" onClick="changeColor(this.id)"&gt;B1&lt;/button&gt;
&lt;button id="tab2" class="tab" onClick="changeColor(this.id)"&gt;B2&lt;/button&gt;
&lt;button id="tab3" class="tab" onClick="changeColor(this.id)"&gt;B3&lt;/button&gt;
&lt;script type="text/javascript"&gt;
    function changeColor(id) {    
        var tabs = document.getElementsByClassName('tab')
        for (var i = 0; i &lt; tabs.length; ++i) {
            var item = tabs[i];
            item.style.backgroundColor = (item.id == id) ? "white" : "silver";
        }
    }
&lt;/script&gt;


see fiddle - http://fiddle.jshell.net/vP7ku/

must shorter, Hua?