Opening tab with anchor link

You could solve this by simply checking the hash when the page loads, and then trigger a click on the right tab, like so:

$(function () {
    $(".tab-content").hide().first().show();
    $(".inner-nav li:first").addClass("active");

    $(".inner-nav a").on('click', function (e) {
        e.preventDefault();
        $(this).closest('li').addClass("active").siblings().removeClass("active");
        $($(this).attr('href')).show().siblings('.tab-content').hide();
    });

    var hash = $.trim( window.location.hash );

    if (hash) $('.inner-nav a[href$="'+hash+'"]').trigger('click');

});

Leave a Comment