Jquery linking to another tab -
i have tabs working fine , adding 'active' class when clicked. want have text links within tabs content linking each other. have working can't find way tab active:
jsfiddle: http://jsfiddle.net/sarah3585/01vas55s/
so here want apply active class tab2 when link clicked within tab1.
html:
<div class="tabs"> <div class="selection"> <ul class="tab-links"> <li class="active"><a class="tab-link button" href="#tab1">button1</a></li> <li><a class="tab-link button" href="#tab2">button 2</a></li> </ul> </div> <div class="internal-container tab-content"> <div id="tab1" class="tab active"> tab 1 content <a href="#tab2" class="tab-link">link tab2</a> </div> <div id="tab2" class="tab"> tab 2 content </div> </div> </div>
js:
$(document).ready(function() { $('a.tab-link').on('click', function(e) { var currentattrvalue = $(this).attr('href'); // show/hide tabs $('.tabs ' + currentattrvalue).show().siblings().hide(); // change/remove current tab active $(this).parent('li').addclass('active').siblings().removeclass('active'); e.preventdefault(); }); });
replace
$(this).parent('li').addclass('active').siblings().removeclass('active');
with
$('a[href='+currentattrvalue+']').parent('li').addclass('active').siblings().removeclass('active');
Comments
Post a Comment