Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8105975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:19:11+00:00 2026-06-06T00:19:11+00:00

I have some jQuery tabs on a website and I am trying to make

  • 0

I have some jQuery tabs on a website and I am trying to make the tabs so they can be linked to directly.

What I mean by this is that, when a user enters a URL that includes the anchors for the tab, then when the page is loaded is should display that tab first.

My original jQuery code was gotten from http://jqueryfordesigners.com/jquery-tabs/ and did not include this ability. Here is the original code:

$(function () {
    var tabContainers = $('div.tabs > div');

    $('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();

        $('div.tabs ul.tabNavigation a').removeClass('selected');
        $(this).addClass('selected');

        return false;
    }).filter(':first').click();
});

I have modified the code to this:

$(function () {
    var tabs = [];
    var tabContainers = $('div.tabs > div');
    $('div.tabs ul.tabNavigation a').each(function () {
        if (this.pathname == window.location.pathname) {
            tabs.push(this);
            tabContainers.push($(this.hash).get(0));
        }
    });

// sniff for hash in url, and create filter search 
var selected = window.location.hash ? '[hash=' + window.location.hash + ']' : ':first'; 

$(tabs).click(function () {
    // hide all tabs
    $(tabContainers).hide().filter(this.hash).show();        
    // set up the selected class
    $(tabs).removeClass('selected');
    $(this).addClass('selected');        
    return false;
}).filter(selected).click();


});

This kind of works – when you link to the page with the anchor included in the URL, it brings you to the relevant tab’s content, however, and other tabs are visible also (its not hidden the others) and the tab has also not been selected.

You can view an example of this:

No link to second tab, first one shown by default: http://74.54.17.66/~innovarc/improve/success-stories/financial-performance/

Trying to link directly to the second tab: http://74.54.17.66/~innovarc/improve/success-stories/financial-performance/#financial-performance

I have tried to figure out what is wrong with the jQuery code but I cannot figure it out. I would appreciate help with a solution

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:19:13+00:00Added an answer on June 6, 2026 at 12:19 am

    i edited your code to create a working example here (url with hash):

    http://chrisvillanueva.com/stackoverflow/tabs.html#financial-performance

    here’s how i made it work:

    1.) remove .filter() and .click() methods chained with the "div.tabs ul.tabNavigation a" click event handler. those methods always cause the first tab to get focus.

    2.) create a selected tab hash like this:

    var selectedTab = window.location.hash ? window.location.hash : '#cost-improvement';
    

    "selectedTab" will contain the value we use for tab #id reference.

    3.) then initialize the requested tab with these lines:

    //initalizes tab in url
      $('div.tabs ul.tabNavigation li'+selectedTab+' a').addClass('selected');
      tabContainers.hide().filter($(''+selectedTab+'-tab')).show();
    

    4.) in the tab markup, define each list item element with this syntax:

    <li id="financial-performance"><a href="#financial-performance-tab">Second</a></li>
    

    where the li contains a unique id and the anchor element references the related tab.

    5.) setup your tab panel markup like this:

    <div id="financial-performance-tab">
           <h2>Second</h2>
            ....
    

    of course, it helps more if you look at the source for the page i linked. it will give you better context.

    quick note: valid url hash values are:

    • cost-improvement

    • financial-performance

    • change-management

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some <div id=hideclass> in jquery tabs. i want it can hidden or
Hello I have a page with some jquery ui tabs on it and they
I have some tabs using jQuery UI which work just fine, but I want
I have some jquery code that is doing an ajax lookup and returning comma
I have some jQuery code that highlights a link when clicked, and changes the
I have some jquery code which I am trying to translate to YUI. I
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have some jQuery code that is having difficulty running because I'm using it
I have some jQuery tabs one of which holds a flash video. When I
I have some jquery tabs on my page the code for them is: //tabs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.