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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:50:29+00:00 2026-05-29T17:50:29+00:00

My code has a delay in loading a file. I have to click <a

  • 0

My code has a delay in loading a file. I have to click <a href="#string" id="hash"></a>
twice to make it show the .txt file.

The code:

<script type='text/javascript'>
  $(document).ready(function(){
    $("a#hash").click(function(){
      var loc = $(window)[0].location;
      var getUrlString = $(loc).prop('hash').substr(1);
      $("p").load(getUrlString + '.txt');
    });
  });
</script>

<body>
  <p>This is a placeholder for your content</p>
  <a id="hash" href="#login">Login</button><br />
  <a id="hash" href="#register">Register</button><br />
  <a id="hash" href="#recovery">Recovery</button> 
</body>

For example if i click login the first time the page has loaded – it wont show anything.
If i click Register after clicking Login – it will show Login.
If i click Recovery after clicking Register – it will show Register, but if i click Recovery again it will finally show Recovery.

Sorry for my bad english, or if it’s hard to understad what’s my problem. I’m still learning jQuery, and i find it easier to learn if i try/fail myself, and then find out what’s the problem. By just reading tutorials it’s not the same 🙂

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-29T17:50:35+00:00Added an answer on May 29, 2026 at 5:50 pm

    First of all, the ID should never be repeated within your page. If you need to group elements by an identifier, use a class.

    Secondly the problem with the method you have now is that it will read the URL of the window BEFORE it changes to reflect the new URL in the a which was clicked. This is why you’re seeing the content from the click before appearing. If you need to get the hash value of the URL, it is much easier and simpler to get it from the href attribute of the link which was clicked.

    With that in mind, try this:

    <script type='text/javascript'>
        $(document).ready(function(){
            $("a.hash").click(function() {
                var textfileName = $(this).attr("href").replace("#", "");
                $("p").load(textfileName + '.txt');
            });
        });
    </script>
    
    <body>
        <p>This is a placeholder for your content</p>
        <a class="hash" href="#login">Login</button><br />
        <a class="hash" href="#register">Register</button><br />
        <a class="hash" href="#recovery">Recovery</button> 
    </body> 
    

    Example fiddle

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

Sidebar

Related Questions

My code has something like this: HttpFileCollection files Instead of looping through each file
I have heard of desktop applications whose code has been open-sourced, but are there
I have the following code: $('#DoButton').click(function (event) { event.preventDefault(); $(input:checked).each(function () { var id
I have a flash file that has three main buttons on top. When a
This is my code currently: $(function() { $('#header_left').click(function(){ $('#header_left_info').fadeOut('fast'); $('#header_left').fadeOut('fast'); $('#header_left_back').delay(250).fadeIn('fast'); }); }); (the
This code has an interesting bug: some_struct struct_array1[10] = {0}; some_struct struct_array2[10] = {0}
The code has a runtime dependency which is not available in our development environment
The following code has a simple binding which binds the Text of the TextBlock
So this code has the off-by-one error: void foo (const char * str) {
If my Perl code has a production code location and "beta" code location (e.g.

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.