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

  • Home
  • SEARCH
  • 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 6152605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:56:54+00:00 2026-05-23T19:56:54+00:00

There are many tutorials that show you how to create an active tab effect

  • 0

There are many tutorials that show you how to create an active tab effect in a navigation bar by fetching the # from the url.

This is great if you are linking to the same page, but what if all your links are on different pages. Is there a way using Jquery to fetch the url and make the tab active?

The following example gives the specific tab a class “active”:

var tabs = $('ul.tabs');

    tabs.each(function(i) {
        //Get all tabs
        var tab = $(this).find('> li > a');
        tab.click(function(e) {

            //Get Location of tab's content
            var contentLocation = $(this).attr('href') + "Tab";

            //Let go if not a hashed one
            if(contentLocation.charAt(0)=="#") {

                e.preventDefault();

                //Make Tab Active
                tab.removeClass('active');
                $(this).addClass('active');

                //Show Tab Content & add active class
                $(contentLocation).show().addClass('active').siblings().hide().removeClass('active');

            } 
        });

How do I modify this to work with links to other pages within my site? Here is the html:

<ul id="nav"  class="tabs">
    <li><a href="/" title="Home" class="active">Home</a></li>   
    <li><a href="/about/" title="About us">About</a></li>
    <li><a href="/demo/" title="Demo">Demo</a></li>
    <li><a href="/where/" class="dir" title="Where">Where</a></li>
    <li><a href="/contact/" class="dir" title="Contact Us">Contact Us</a></li>
</ul>

The above jquery only works for #tab1, #tab2 etc, how do I make the tab active depending on the current page name? Sorry if this is a little unclear, it’s quite hard to explain!

  • 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-05-23T19:56:55+00:00Added an answer on May 23, 2026 at 7:56 pm

    On the load of the page you can check the ‘window.location’ object for what page is being displayed, and then set the ‘active’ class to the corresponding link:

    $(document).ready(function () {
        //iterate through your links and see if they are found in the window.location.pathname string
        var loc_href = window.location.pathname;
        $('#nav a').each(function () {
            if (loc_href == $(this).attr('href')) {
                $(this).addClass('active');
            }
        });
    });
    

    NOTE: that the loc == $(this).attr(‘href’) line looks to see if the href values for the links exactly match the window.location.pathname string.

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

Sidebar

Related Questions

There are many tutorials that show you how to create the model instructions for
There are many tutorials that talk about deleting index.php from the url. But I
What I need ok I googled this and there are many tutorials on how
I know there are many tutorials out there for getting started in C. However
There are many techniques to enforce strong passwords on website: Requesting that passwords pass
There are many different styles of variable names that I've come across over the
There are many usability evaluation techniques that have been developed over the history of
I've seen many tutorials online that says you need to check $_SERVER['HTTPS'] if the
I see there are many tutorials about nhibernate but I cannot find a descent
I'm getting frustrated at this. I want to create an iPhone application to show

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.