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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:11:06+00:00 2026-06-14T06:11:06+00:00

When I do this, location.hash = test the url is updated and the page

  • 0

When I do this,

location.hash = "test"

the url is updated and the page homes in on the element with that id.

Is there a way to stop the page from homing in to that element?

  • 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-14T06:11:07+00:00Added an answer on June 14, 2026 at 6:11 am

    Solution

    You cannot prevent this behaviour, but you can fool it by temporarily hiding the target, eg. like that (it has nothing to do with jQuery):

    // obtain "target" DOM (not jQuery) element and do this:
    var original_id = target.id; // save original ID
    target.id = null; // set target's ID
    location.hash = 'test'; // issue location.hash change
    target.id = original_id; // set ID to original value
    

    Generalized solution

    Or more general example:

    // make target_hash set to a hash you want to not lead you to page section and:
    var element = document.getElementById(target_hash); // find element by ID
    var original_id = element.id; // save original ID
    location.hash = target_hash; // previously defined by you (eg. 'test')
    element.id = original_id; // reset ID
    

    Demo / proof

    The live example can be as follows, in the event handler attached through jQuery (demo here: http://jsfiddle.net/DaZfH/):

    some_link.on('click', function(event){
        event.preventDefault();
        var target = document.getElementById('target');
        var original_id = target.id;
        target.id = null; // unset ID
        location.hash = 'target';
        target.id = original_id;
    });
    

    Disclaimer

    But indeed others are right: moving you to the correct place in the document is the correct behaviour. If you are doing things like I mentioned, then your solution is pretty hakish and there is definitely a better way to do that.

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

Sidebar

Related Questions

I wrote this quick jquery tab code that also updates the hash location (appended
document.location.hash= sets the hash to # in the URL. But when I run this
In firefox, using this javascript: top.location.hash = #here%20are%20spaces; changes the browser url to: http://mysite.com/#here
Right now I'm using if(window.location.hash != '') Is this foolproof? Or, is there a
I have a requirement in a shell script. I get this location information from
I have a model that looks like this: Performance - Location - Event -
I'm trying to match the hash fragment of a jQuery Mobile URL like this:
I'm trying to extract hash substring values from window.location and write them into HTML
I have a statement like this: if(window.location.hash != '' && window.location.hash != '#all' &&
OK so whenever I want to change my URL with hash, I do this:

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.