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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:20:05+00:00 2026-05-24T12:20:05+00:00

Possible Duplicate: How do I stop a web page from scrolling to the top

  • 0

Possible Duplicate:
How do I stop a web page from scrolling to the top when a link is clicked that triggers javascript?

When I click on a date of a jQuery datepicker on my web page, my page repositions itself to the top because the date on the datepicker has an href="#" attribute.

It seems that whenever I click an <a> element that has href="#" then my page reorientates iteself to display from the top of the page. This is pretty annoying because the user is having to cope with the page moving about and may even have to scroll just to see the part of the page they were using before they clicked. Can anyone tell me how I can stop this from happening?

I can take the href attribute from some of my links, but jQuery widgets often have them in.

Many 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-24T12:20:06+00:00Added an answer on May 24, 2026 at 12:20 pm

    Usually when a link has href="#", it’s because it’s supposed to do something other than navigating (the exception being “To the top” links seen on some long pages…). The “other thing” they’re doing is usually handled via JavaScript, and to make sure that they don’t continue to their default handler (i.e. navigate) the JS handler should return false.

    If you make sure that all your click handlers return false, you won’t have this problem anymore.

    If you’re using jQuery to hook up your events, you could also call .preventDefault() and .stopPropagation() on the first argument to the click handler function. This will do it on it’s own in most browsers, but you should still return false for compatibility.

    $('.someLink').click(function(ev) {
        // do your thing
    
        // Prevent the click from being handled.
        ev.preventDefault();
        // Prevent the event from propagating through the DOM tree (bubbling)
        ev.stopPropagation();
        // Return false, for compatibility reasons
        return false;
    });
    

    Note: If there are click handlers in some library you’re using that doesn’t return false, you can always wrap it in a handler function of your own that does. But I’d consider abandoning that library…

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

Sidebar

Related Questions

No related questions found

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.