What i want is hide all content first, then click one tab, the corresponding content shows (the tab becomes ‘active’), where click it again it will disappear. some of the tabs are just a ‘mailto’ link.
problem is i can’t hide the tabs when click again
$(document).ready(function(){
$('#nav div').hide();
$('#nav div:first').show();
$('#nav ul li:first').addClass('active');
$('#nav ul li a').click(function(){
$('#nav div').hide();
$('#nav ul li').removeClass('active');
$(this).parent().addClass('active');
var currentTab = $(this).attr('href');
if($(currentTab).css('display')=='none'){
$(currentTab).show();
}else{
$(currentTab).hide();
}
}
);
});
the navigation code is the following:
<div id="nav">
<ul>
<li><a href="#about">About</a></li>
<li><a href="mailto:email">Email</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div id="about">
about
</div>
<div id="contact">
contact
</div>
</div>
This should work:
you have to check if the current tab is visible before you hide it.
working: http://jsfiddle.net/tqhHA/