 <p>If you can update the elements to have a common class, e.g., <code>class="state"</code>, then:</p> <pre><code>var SetState = function(state) { var s = document.getElementsByClassName("state"), i; for (i=0; i &lt; s.length; i++) s[i].style.display = 'none'; document.getElementById(state).style.display = 'block'; }; </code></pre> <p>That is, loop through all elements with the <code>state</code> class and hide them, then show just the one that was passed into the function with:</p> <pre><code>SetState('ohio'); </code></pre> <p>Alternatively, if you can't change the html, put all the state names in an array and loop through the array to hide them.</p>