Skip to content

Instantly share code, notes, and snippets.

@bnecreative
Last active April 16, 2022 01:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnecreative/8c7cc3598a1d18cee246 to your computer and use it in GitHub Desktop.
Save bnecreative/8c7cc3598a1d18cee246 to your computer and use it in GitHub Desktop.
Deeplink to Bootstrap Tabs
jQuery(document).ready(function($){
// Allow Page URL to activate a tab's ID
var taburl = document.location.toString();
if( taburl.match('#') ) {
$('.nav-tabs a[href="#'+taburl.split('#')[1]+'"]').tab('show');
}
// Allow internal links to activate a tab.
$('a[data-toggle="tab"]').click(function (e) {
e.preventDefault();
$('a[href="' + $(this).attr('href') + '"]').tab('show');
});
}); // End
<!-- This is how I structure my bootstrap tabs in my WordPress Themes. Your markup may be different. -->
<p>Here's a <a href="#my_tab3" data-toggle="tab">link</a> Jump to Tab #3.</p>
<div class="tabbable bne-tabs-framed tabs-above clearfix">
<ul class="nav nav-tabs">
<li class=""><a href="#tab_893" data-toggle="tab"> Tab Title #1</a></li>
<li class=""><a href="#my_tab2" data-toggle="tab"> Tab Title #2</a></li>
<li class=""><a href="#my_tab3" data-toggle="tab"> Tab Title #3</a></li>
</ul>
<div class="tab-content">
<div id="tab_893" class="tab-pane fade clearfix">Tab 1 content…..&nbsp;Donec ullamcorper nulla non metus auctor fringilla. Aenean lacinia bibendum nulla sed consectetur. Sed posuere consectetur est at lobortis.</div>
<div id="my_tab2" class="tab-pane fade clearfix">Tab 2&nbsp;content…..&nbsp;Donec ullamcorper nulla non metus auctor fringilla. Aenean lacinia bibendum nulla sed consectetur. Sed posuere consectetur est at lobortis.</div>
<div id="my_tab3" class="tab-pane fade clearfix">Tab 3content…..&nbsp;Donec ullamcorper nulla non metus auctor fringilla. Aenean lacinia bibendum nulla sed consectetur. Sed posuere consectetur est at lobortis. <a href="#my_tab2" data-toggle="tab" aria-expanded="false">Go back</a> to tab #2.</p></div>
</div>
</div>
@sparkitect
Copy link

brilliant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment