I think that the slice() is a bit hacky, and prone to breaking if I change my mind about the id names, but I wanted this to be generic so I could add types easily.
Is there maybe another / better way to do this just using CSS nesting the 'panels' inside the li elements?
Markup:
<ul id="type-select">
<li><a id="type-1" href="#">1</a></li>
<li><a id="type-2" href="#">2</a></li>
...
</ul>
<div id="panel-1" class="panel">blah</div>
<div id="panel-2" class="panel">blah</div>
...
JavaScript:
function switchType(type){
$("#type-select li a").removeClass("selected-type");
$("#type-"+type).addClass("selected-type");
$(".panel").removeClass("selected-panel");
$("#panel-"+type).addClass("selected-panel");
}
// initial state
$("#no-results").hide();
switchType("1");
$("#type-select li a").click(function(){switchType(this.id.slice(5))});