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 8299479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:10:17+00:00 2026-06-08T16:10:17+00:00

I have the following code: fiddle , how can I set it up so

  • 0

I have the following code: fiddle, how can I set it up so I can have urls to the different tabs, I have tried adding the tab id to the url and that doesn’t work. I have also tried anchors and that doesn’t work, any help appreciated.

  • 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-08T16:10:20+00:00Added an answer on June 8, 2026 at 4:10 pm

    You can do this very easy. As your list is corresponding to the tabs semself in the order of appearance you don’t need the ids and you can do it like this:

    HTML

    <ul id="tabs">
        <li><a href="http://domain.com/#tab1">test1</a></li>
    </ul>
    
    <div>
          <div class="container">Some content1</div>
    </div>
    

    JavaScript

    var tabs = $('#tabs a');
    var content = $('.container');
    var current = 0;
    
    tabs.click( function(event) {
        // get which element was clicked
        var pos = tabs.index ($(event.target) );
        // remove current active class
        tabs.eq(current).removeClass('active');
        // fade out current element
        content.eq(current).fadeOut( function() {
            //afterwards set current to selected, update class and fade in content
            current = pos;
            tabs.eq(current).addClass('active');
            content.eq( current ).fadeIn();
            // append hash to url
            window.location.hash = tabs.eq(current).attr('href');
        });
    
        event.preventDefault();
    });​
    

    This is the line that adds the anchor to the URL:

    window.location.hash = tabs.eq(current).attr('href');
    

    Note, that this won’t work in the fiddle. Or you can leave this line out and add real urls like I did in the source code above.

    I also optimized your code, in order that uses less selectors and it’s a little shorter. And it also uses a single class active for the current element (instead of applying a class to all inactive elements). You just have to adjust your styles.

    I also added some CSS which shows the first element by default and hides all other – no JavaScript needed:

    .container {
        display:none;
    }
    
    .container:first-child {
        display:block;
    }
    

    Fiddle

    http://jsfiddle.net/insertusernamehere/hCWMj/

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

Sidebar

Related Questions

I have the following code: JS Fiddle I want that on hover the background
I have following code for loading image from url in xml parsing endElement method
I have following code. ASPX Page <a href=AnyASPXPageOfWebsite.aspx onclick=javascript:CallJQuery(); > Set Price </a> JS
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code: def whatever(url, data=None): req = urllib2.Request(url) res = urllib2.urlopen(req, data)
I have the following javascript code found also in this fiddle: http://jsfiddle.net/periklis/k4u4c/ <button id
I have the following code that should insert two fields into a database via
I have the following fiddle setup http://jsfiddle.net/Wap43/3/ I can't get the bars to shade.
I have the following as part of some code - you can see it
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig

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.