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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:50:19+00:00 2026-05-14T18:50:19+00:00

I am using a bit of JavaScript to show/hide sections of a site when

  • 0

I am using a bit of JavaScript to show/hide sections of a site when a tab is clicked. I’m trying to figure out if there is a way I can link back to the page and have a certain tab open based on that link.

Here is the JS:

   var ids=new Array('section1','section2','section3','section4');

function switchid(id, el){  
    hideallids();
    showdiv(id);

    var li = el.parentNode.parentNode.childNodes[0];
    while (li) {
        if (!li.tagName || li.tagName.toLowerCase() != "li")
            li = li.nextSibling; // skip the text node
        if (li) {
          li.className = "";
          li = li.nextSibling;
        }
    }
    el.parentNode.className = "active";
}

function hideallids(){
    //loop through the array and hide each element by id
    for (var i=0;i<ids.length;i++){
        hidediv(ids[i]);
    }         
}

function hidediv(id) {
    //safe function to hide an element with a specified id
        document.getElementById(id).style.display = 'none';
}

function showdiv(id) {
    //safe function to show an element with a specified id        
        document.getElementById(id).style.display = 'block';
}

And the HTML

<ul>
<li class="active"><a onclick="switchid('section1', this);return false;">One</a></li>
<li><a onclick="switchid('section2', this);return false;">Two</a></li>
<li><a onclick="switchid('section3', this);return false;">Three</a></li>
<li><a onclick="switchid('section4', this);return false;">Four</a></li>
</ul>

<div id="section1"  style="display:block;">   
<div id="section2" style="display:none;">  
<div id="section3" style="display:none;">  
<div id="section4" style="display:none;">

I haven’t been able to come up with a way to link back to a specific section. Is it even possible with this method?

Thanks!

  • 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-14T18:50:20+00:00Added an answer on May 14, 2026 at 6:50 pm

    You could run some script when your page loads that checks the url hash & loads the appropriate section:

    // on page load
    var sectionid = /section\d/i.exec(location.hash);
    if (sectionid) {
        var link = document.getElementById(switchid[0] +"_link");
        switchid(sectionid[0], link);
    }
    

    & add an id to your links:

    <li><a id="section2_link" onclick="switchid('section2', this);return false;">Two</a></li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a quiz program using PHP and a bit of Javascript. The questions
I am using jquery to load content into tabs, and switch the tabs on
The website to see the error (click the home, models, etc links) : http://bit.ly/9AE2RI
I am fairly new to Jquery and javascript and have jumped in head first
I am using jquery to post vars to a php script. Is it possible
Traditionally, to call a JavaScript function once the page has loaded, you'd add an
I have a scrollable area that contains popup menus. Conceptually, something like this: <div
I'm working on a project where I need to make a Flex application that
I have an approach in mind for an image viewer in a web app,
I'm a member of a small but fairly sociable online forum, and just for

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.