Javascript tab help (Go to last selected tab upon refresh)

This project was awarded to sanjuintelligo for $30 USD.

Get free quotes for a project like this
Employer working
Awarded to:
Project Budget
$30 - $250 USD
Total Bids
Project Description

I decided to find some javascript code online that allowed me to create "tabs" into different divs.

The problem is that when I refresh the page, it automatically goes back to the first tab. I've tried all different variations of the code, but not coming with the answer. I also tried setting the "currentTab" as the last clicked, but I think I'm just not using correct syntax because currentTab doesn't get created until the tab is clicked.

Anyway, here's the code:

<script type="text/javascript">


$('#user_content .maintab').hide(); // Hide all divs that are 'hideable'

$('#user_content #top').show();

$('#user_content div:first').show(); // Show the first div

$('#user_content ul li:first').addClass('first'); // Set the class of the first link to active

$('#user_content ul li a').click(

function(){ // When any link is clicked

$('#user_content ul li').removeClass('active'); // Remove active class from all links

$('#user_content ul li').removeClass('first');






$(this).parent().addClass('active'); // Set clicked link class to active


var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link


$('#user_content .maintab').hide(); // Hide all divs that are 'hideable'

$('#user_content #top').show();

$(currentTab).show(); // Show div with id equal to variable currentTab

return false;




If you can help me fix this small issue that'd be great. I will not accept any bids that are more than the minimum amount. This job is too small to give anymore than that. Thanks

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online