I have a navigation, with a sprite that changes based on the class. In my jquery, I'm clearing out he classes so it will just have .nav then addClass the right class based on the click. It works but feels very redundant. Just seeing if anyone has suggestions of optimizing this ?
HTML:
<div class="grid_12 nav home">
<ul class="tabs">
<li class="home"><a href="javascript:;">HOME</a></li>
<li class="game-stats"><a href="javascript:;">GAME STATS</a></li>
<li class="game-talk"><a href="javascript:;">GAME TALK</a></li>
<li class="game-info"><a href="javascript:;">GAME INFO</a></li>
</ul>
</div>
JS:
$('DIV.content DIV.nav ul li.home').click(function(){
$('DIV.content DIV.nav').attr('class', 'nav');
$('DIV.content DIV.nav').addClass('home');
});
$('DIV.content DIV.nav ul li.game-stats').click(function(){
$('DIV.content DIV.nav').attr('class', 'nav');
$('DIV.content DIV.nav').addClass('gamestats');
});
$('DIV.content DIV.nav ul li.game-talk').click(function(){
$('DIV.content DIV.nav').attr('class', 'nav');
$('DIV.content DIV.nav').addClass('gametalk');
});
$('DIV.content DIV.nav ul li.game-info').click(function(){
$('DIV.content DIV.nav').attr('class', 'nav');
$('DIV.content DIV.nav').addClass('gameinfo');
});
grid_12
class when you click on something? – 32bitkid Jan 4 '12 at 18:43grid_12
class supposed to go away when you click a link? – 32bitkid Jan 4 '12 at 19:16