jmiller
jmiller

Reputation: 588

How to link to navtab in bootstrap?

I have a series of tabs i have created using navtabs in bootstrap. I was wondering is it possible to link (hyperlink) directly to one tab? For example <a href="page.html#tab1">link to tab 1</a>

Thanks.

Upvotes: 0

Views: 87

Answers (2)

jmiller
jmiller

Reputation: 588

Solution:

<script type='text/javascript'>var tabs$ = $(".nav-tabs a");

$( window ).on("hashchange", function() {
    var hash = window.location.hash, // get current hash
        menu_item$ = tabs$.filter("[href=" + hash + "]"); // get the menu element

    menu_item$.tab("show"); // call bootstrap to show the tab
}).trigger("hashchange");</script>

Upvotes: 0

Abdul Basit
Abdul Basit

Reputation: 374

Try this javascript

var url = document.location.toString();
if (url.match('#')) {
    $('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ;
} 

Upvotes: 1

Related Questions