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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:03:16+00:00 2026-06-10T09:03:16+00:00

I am trying to link anchors inside jquery tabbed content. I have gotten it

  • 0

I am trying to link anchors inside jquery tabbed content. I have gotten it to work, however, now when I click on tabs the page jumps to the top of the tab-content div, and cuts off tabs. I would like it to stay in the same spot without scrolling when tabs are clicked. I also need to access each tab and inside anchor from a URL, just need the tab URL to not jump to top of tab-content div, cutting off tabs on top. example: http://mysite.com/test#tab1

Here is what I have so far:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

$(function() {
$('a.refresh').live("click", function() {
      location.reload();
});
 });
</script>

<section class="wrap">

<div class="tablist">
<ul class="tabs">
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>

</ul>
</div>
<div class="panes">
<div id="tab1" class="tab-content">
Tab 1 content
<br />
<a name="anchor1" id="anchor1">Anchor 1</a>
</div>

<div id="tab2" class="tab-content">
Tab 2 content
</div>

<div id="tab3" class="tab-content">
Tab 3 content
<br />
<a name="anchor2" id="anchor2">Anchor 2</a>
</div>

</div>
</section>

<script type="text/javascript">
$(document).ready(function() {
var $tabContent = $(".tab-content"),
    $tabs = $("ul.tabs li"),
    tabId;

$tabContent.hide();
$("ul.tabs li:first").addClass("current").show();
$tabContent.first().show();

$tabs.click(function() {
    var $this = $(this);
    $tabs.removeClass("current");
    $this.addClass("current");
    $tabContent.hide();
    var activeTab = $this.find("a").attr("href");
    $(activeTab).fadeIn();

});

// Grab the ID of the .tab-content that the hash is referring to
tabId = $(window.location.hash).closest('.tab-content').attr('id');

// Find the anchor element to "click", and click it
$tabs.find('a[href=#' + tabId + ']').click();
 })

$('a').not('.tabs li a').on('click', function(evt) {
evt.preventDefault();
var whereTo = $(this).attr('goto');
$tabs = $("ul.tabs li");
$tabs.find('a[href=#' + whereTo + ']').trigger('click');

$('html, body').animate({
    scrollTop: $('#'+whereTo+' a').offset().top });


 });
 </script>

Any thoughts, ideas, or help would be much appreciated!!

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-06-10T09:03:22+00:00Added an answer on June 10, 2026 at 9:03 am

    You need to add this to the event to stop its default behavior

    preventDefault();
    

    See the documentation

    So for any anchor tag that you need to stop its behavior

    $('#yourselector').click(function(e){
        e.preventDefault();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to convert my rails 2.2.2 app over to jQuery, and
I am trying to display a DataTable inside a Jquery Tab that is loaded
I am trying to perform an action on link click.In this case I want
I'm creating a jQuery Mobile web application. This link, works correctly: <a href=/ThePage/25 data-transition=slidedown>Click
I am trying to create a link which when clicked shows some info inside
I am trying to append the text of a link inside a <li> to
I'm trying to have just one link on my website that links to the
I am trying to place a link into an Extinfowindow that obtains its content
I want to integrate tweet button inside a jquery template. Am trying the 'tweet
I am trying to set click handler for an anchor tag in jQuery mobile

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.