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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:16:30+00:00 2026-05-23T23:16:30+00:00

I am using jquery to load a sidebar into each of my pages, the

  • 0

I am using jquery to load a sidebar into each of my pages, the sidebar contains a list of story names, the date, and the content type (story, article, news, whatever) which is placed in an unordered list, when each page loads I use jquery’s .load() function to load the sidebar information into the current page’s unordered list, once the sidebar information has loaded I use another script which sets the href of the current story in the sidebar to #. The problem is that the piece of code that sets the href to # only works if I put an alert right before the function.

Here is the flow:

user clicks on a story (lets call the story nothing.html)

nothing.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="../../../../css/reset.css">
    <link rel="stylesheet" href="../../../../css/index.css">
    <script type="text/javascript" src="../../../../js/jquery.js"></script>
    <script type="text/javascript" src="../../../../js/storyLoadSidebar.js"></script>
    <script type="text/javascript" src="../../../../js/disableLink.js"></script>
    <title> Nothing </title>
</head>

<body>

    <div id="container">

        <div id="main">

            <article>

                <header>
                    <h3> Nothing Here </h3>
                    <time pubdate="pubdate"> July 19, 2011 </time>
                </header>

                <p> I said there was nothing here, yet. </p>

            </article>

        </div>

        <div id="listWrapper">
            <div id="storyList">
                <ul></ul>
            </div>
        </div>

    </div>

</body>

</html>

storyLoadSidebar.js

$(document).ready(function() {
    $("ul").load("../../../../sidebar.html ul");
});

sidebar.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
</head>

<body>  

    <ul>

        <li>
            <div class="catDate">
                <p> Nothing </p>
                <time pubdate="pubdate"> 2011-07-19 </time>
            </div>

            <div class="storyTitle">
                <a id="nothing" href="stories/2011/07/19/nothing.html"> Nothing Here, Yet. </a>
            </div>
        </li>

    </ul>

</body>

</html>

then finally the script to disable the link:

disableLink.js

$(document).ready(function() {
    var fullPath = window.location.pathname;
    var pageName = fullPath.substring(fullPath.lastIndexOf('/') + 1).replace('.html', '');
    $('#' + pageName).attr('href', '#');
});

The entire thing only works of I add an alert to disableLink.js right before the href modification like so:

$(document).ready(function() {
    var fullPath = window.location.pathname;
    var pageName = fullPath.substring(fullPath.lastIndexOf('/') + 1).replace('.html', '');
    alert('now it will work');
    $('#' + pageName).attr('href', '#');
});

What is the problem here, why does it only work if I add in an alert?

  • 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-23T23:16:30+00:00Added an answer on May 23, 2026 at 11:16 pm

    The reason is $("ul").load("...") takes some time to load.

    You can assign it a call back function so the next piece of code only runs when it is completed

    $("ul").load("../../../../sidebar.html ul",function () {
       var fullPath = window.location.pathname;
       var pageName = fullPath.substring(fullPath.lastIndexOf('/') + 1).replace('.html', '');
       $('#' + pageName).attr('href', '#');
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery load to load php pages into my content area. I
When using jQuery.load to dynamically load HTML content into a webpage, what is the
I am using JQuery to load content into a div element and everything is
I am using jQuery load() function to load some pages into container. Here is
I was using jQuery.load() to load a html page's content into a lightbox. The
We are using jquery to .load() a form into a div We then use
I'm using JQuery to load the content of an MVC usercontroll: function menuShowModal(a) {
I'm trying to load some external content using jQuery load function to div on
I am using jQuery load() to load more content when the user scrolls to
So I am using load functions of jQuery to use ajax on my pages.

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.