1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
<div class="tabs"> <ul> <li><a class='tab1_link' href='#'>Tab 1</a></li> <li><a class='tab2_link' href='#'>Tab 2</a></li> <li><a class='tab3_link' href='#'>Tab 3</a></li> </ul> <div class='tab1' >content for tab 1</div> <div class='tab2' >content for tab 2</div> <div class='tab3' >content for tab 3</div> </div>
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
$('.tab2').hide(); $('.tab3').hide(); $('.tab1_link').click(function(e){ $('.tab1').show() $('.tab1').siblings().hide() e.preventDefault(); }) $('.tab2_link').click(function(e){ $('.tab2').show() $('.tab2').siblings().hide() e.preventDefault(); }) $('.tab3_link').click(function(e){ $('.tab3').show() $('.tab3').siblings().hide() e.preventDefault(); })
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
<div class="tabs"> <ul> <li><a class='tab_link' rel='tab1' href='#'>Tab 1</a></li> <li><a class='tab_link' rel='tab2' href='#'>Tab 2</a></li> <li><a class='tab_link' rel='tab3' href='#'>Tab 3</a></li> </ul> <div id='tab1' class='tab'>content for tab 1</div> <div id='tab2' class='tab'>content for tab 2</div> <div id='tab3' class='tab'>content for tab 3</div> </div> $('tab_link').click(function(e){ $this = $(this); // this is the link that was clicked. // hide all tabs. $(".tab").hide(); $('#' + $this.attr('rel').val() ).show(); // show the clicked tab. e.preventDefault(); })