Click function inside for loop
<p>I am trying to loop my .hide() and .show() click handlers and I can't get this simple part to work correctly. My buttons are called "#towelcome" etc. I'm assuminig I'm missing something stupid and obvious. All of the divs are hidden in css. </p>

<pre><code>var elements = ["welcome", "slides", "projects", "pages"];
for (i=0;i&lt;=elements.length-1;i++){ 
    $("#to"+elements[i]).click(function() {
      $("#"+elements[i]).show();
    });
}
</code></pre>

<p>/UPDATE:------------------------------------------------------------------------</p>

<p>The following code is the code I am trying to minify.</p>

<pre><code>$("#toprojects").click(function(){
    $("#projects").show();
    $("#slides").hide();
    $("#pages").hide();
    $("#welcome").hide();
});

$("#toslides").click(function(){
    $("#projects").hide();
    $("#slides").show();
    $("#pages").hide();
    $("#welcome").hide();
});

$("#topages").click(function(){
    $("#projects").hide();
    $("#slides").hide();
    $("#pages").show();
    $("#welcome").hide();
});

if(window.location.hash === "#slides"){
    $("#projects").hide();
    $("#slides").show();
    $("#pages").hide();
    $("#welcome").hide();
}

if(window.location.hash === "#projects"){
    $("#projects").show();
    $("#slides").hide();
    $("#pages").hide();
    $("#welcome").hide();
}

if(window.location.hash === "#pages"){
    $("#projects").hide();
    $("#slides").hide();
    $("#pages").show();
    $("#welcome").hide();
}
</code></pre>

<p>found a related post here and it solved it pretty nicely
<a href="http://stackoverflow.com/questions/494161/jquery-set-click-from-array-loop">jQuery: Set click from array loop.</a></p>
