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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:53:13+00:00 2026-06-01T01:53:13+00:00

I am have an issue with the page reloading. I have written a simple

  • 0

I am have an issue with the page reloading. I have written a simple jQuery script that will tab through content. You can see it in action here: http://www.jonathanmaloy.com/tabstack/

The problem is that the page reloads and starts back at the top. I want to be able to have it stay in the same position so when you click on the next tab you wont have to scroll down the page back to it.

preventDefault() and return false do not fix the problem.

If there is anything else you need let me know but with the above link you can see everything.

Here is my current jQuery code:

$(document).ready(function() {
    $('#tabnav li').click(function() {
        $(this).not('.active').each(function() {
            $('.tab').hide();
            $('#tabnav li.active').removeClass('active');
        });
        $(this).addClass('active'); 
        $($(this).attr('title')).fadeIn(450);
    });
    $('#tabnav li:first').click();
});

Thanks in advance for any help!

  • 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-01T01:53:15+00:00Added an answer on June 1, 2026 at 1:53 am

    Edit: Updated answer based on properly reading the question 🙂

    As discussed in the comments the problem arises when a new tab is shown and a previously shown tab is hidden. The DOM removal of the previous tab shrinks the page which causes the browser to jump to the top of the page which looks like a page reload, when actually it is not.

    The following JavaScript stores the visible tab first and removes it once the new tab has begun to fade in. I also made a few changes to speed up the function by storing some jQuery objects so save re-querying the DOM each time. Also note that you did not need the each() as the same result can be achieved with a different selector, plus in your original code you were effectively hiding all .tab class elements multiple times.

    $(function() {
      var tabItems = $('#tabnav li'); // save looking this up multiple times
      $('.tab').hide(); // hide all initially
    
      $('#tabnav li').click(function() {
        // remove active class from all and store the visible tab
        tabItems.removeClass('active');
        var visibleTab = $('.tab:visible');
    
        // add class to selected list item
        $(this).addClass('active');
    
        $(this.title).fadeIn(450); // show new tab
        visibleTab.hide(); // hide old one (DOM already has new tab in so page height will not shrink)
      });
    
      $('#tabnav li:first').click();
    });
    


    You want to either call event.preventDefault() or add a return false; (you don’t need the event for this one) to the end of the function.

    By default the browser would execute any click functions bound to the element being clicked on and then follow the link (which I assume is href="#" or similar) that causes the browser to reload the page. Since you are binding a function to the click event you are need to stop the click event from continuing and the browser will not continue execution and follow the href.

    JavaScript

    $('#tabnav li').click(function(event) { // <-- added the eventData map
        $(this).not('.active').each(function() {
            $('.tab').hide();
            $('#tabnav li.active').removeClass('active');
        });
        $(this).addClass('active'); 
        $($(this).attr('title')).fadeIn(450);
        event.preventDefault(); // or return false;
    });
    

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

Sidebar

Related Questions

I have this exact issue ASP.net can’t update page from event handler and it's
We have an issue on our page whereby the first time a button posts
I have an issue using jquerys selectors when it comes to a page I
I have a strange issue: I am using SPContext.Current.Web in a .aspx page, but
Please have a look at this page www.pixeli.ca/issue. I have begun making a page
I have a master page which all my views inherit from. The issue I
I have a registration page, and because of content issues we have to request
I have a couple of things I'm working on, namely a page that issues
I have a page that may have 10 or so editable 'panels' of information.
My issue is relating to dynamically applied elements to a page that I am

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.