Skip to content

Instantly share code, notes, and snippets.

@atomrli
Last active January 8, 2019 11:19
Show Gist options
  • Select an option

  • Save atomrli/04a4241df62fa5c326085a6b00d4d566 to your computer and use it in GitHub Desktop.

Select an option

Save atomrli/04a4241df62fa5c326085a6b00d4d566 to your computer and use it in GitHub Desktop.
<div class="container">
<div class="tabs-items">
<div class="tabs-item">
1 tab content
</div>
<div class="tabs-item">
2 tab content
</div>
<div class="tabs-item">
3 tab content
</div>
</div>
<nav class="tabs-nav">
<a href="#">1 tab</a>
<a href="#">2 tab</a>
<a href="#">3 tab</a>
</nav>
</div>
<script>
$('nav.tabs-nav').on('click', 'a:not(.active)', function(e) {
e.preventDefault();
$(this)
.addClass('active').siblings().removeClass('active')
.closest('.container').find('.tabs-items').find('.tabs__item').removeClass('active').eq($(this).index()).addClass('active');
});
$('.tabs-nav').each(function() {
$(this).find('a:first').addClass('active')
});
$('.tabs-items').each(function() {
$(this).find('.tabs__item:first').addClass('active')
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment