1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| $(document).ready(function(){
$('#tabs div').hide(); // Hide all divs
$('#tabs div:first').show(); // Show the first div
$('#tabs ul li:first').addClass('active');// Set the class for active state
// OUT $('#tabs ul li a').click(function(){ // When link is clicked
$('#tabs a').click(function(){ // When link is clicked
$('#tabs ul li').removeClass('active'); // Remove active class from links
// OUT $(this).parent().addClass('active'); //Set parent of clicked link class to active
var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
if( currentTab.charAt(0) == '#'){
$('#tabs div').hide(); // Hide all divs
$(currentTab).show(); // Show div with id equal to variable currentTab
// mise du style sur l'onglet
$('#tabs ul li a').each( function(){
if($(this).attr('href') == currentTab){
$(this).parent().addClass('active'); //Set parent of clicked link class to active
};
});
return false;
}
});
}); |