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.
var elements = ["welcome", "slides", "projects", "pages"];
for (i=0;i<=elements.length-1;i++){
$("#to"+elements[i]).click(function() {
$("#"+elements[i]).show();
});
}
/UPDATE:------------------------------------------------------------------------
The following code is the code I am trying to minify.
$("#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();
}
found a related post here and it solved it pretty nicely jQuery: Set click from array loop