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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:41:46+00:00 2026-06-15T21:41:46+00:00

When I run my page sometimes the getElementById call finds the element and sometimes

  • 0

When I run my page sometimes the getElementById call finds the element and sometimes not. Definitely a timing issue. This only happens in IE9 and not in IE compatbility mode (7 or 8), nor does it happen in any other browsers (Firefox, Opera, Safari, and Chrome). Can’t create a fiddle because when I strip the page down to fit in a fiddle and sandbox it, the problem disappears. My getElementById javascript call is in the head section which, I understand, won’t be able to find the elements at that point unless you wait for them with either DOM readiness or window onload. I tried wrapping my getElementById javascript in jquery’s $(document).ready function, but that didn’t have any effect. I also tried wrapping it in jquery’s $(window).load function which I thought must work, but that had no effect either.

If I try waiting for the element with this window.onload solution (addLoadEvent) ti works and finds it. So why not jquery’s document.ready or window.load APIs?

I did try moving the script down in the page after the html for the tag it references, but that didn’t have any effect as the problem still occurred and it couldn’t find the element. I also moved it to the end, but no effect either. I am confused by this particular result as I thought that moving the javascript to the end would make those elements available (or so I read), but it would appear that is not the case. Anyone know why this is?

I did mention earlier that it’s only happening in IE9. Futhermore, only on the initial page load does the problem typically occur and any page refreshes make the problem go away. Likely due to caching I’m guessing.

I’m using asp.net 4.0, not that it matters (or so I think). The javascript is in the .aspx page above the html section in section and not in an external js file. I did try moving it to an external file just to be thorough, but that didn’t have any effect as expected.

So, in summary,

  1. why are the jquery APIs not working? and
  2. why didn’t moving the javascript down the page (or to the end) work either?

Snippet of the Javascript inside head:

//        addLoadEvent(setupstuff);

//        function addLoadEvent(func)
//        {
//            var oldonload = window.onload;

//            if (typeof window.onload != 'function')
//            {
//                window.onload = func;
//            }
//            else
//            {
//                window.onload = function ()
//                {
//                    if (oldonload)
//                    {
//                        oldonload();
//                    }
//                    func();
//                };
//            }
//        }

    var txtLocation = '<%=txtLocation.ClientID%>';

    // JQuery plugin - JQueryLive (waits for element)
    $('#' + txtLocation).livequery(function ()
    {
        setupstuff();
    });


    //$(document).ready(function () //didn't work
    //$(window).load(function() //didn't work
    function setupstuff()
    {
        // search text watermark toggling
        var hasWatermark = $('#' + txtLocation).hasClass('txtLocationWatermark');

        var searchText;
        if (document.getElementById(txtLocation))
        {
            searchText = document.getElementById(txtLocation).value;
        }
        else
        {
            alert('Element ' + txtLocation + ' not found in DOM!');
            return;
        }
        //var searchText = $('#' + txtLocation).val(); //doesn't work either
  • 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-15T21:41:47+00:00Added an answer on June 15, 2026 at 9:41 pm

    Upgrading to latest version of jQuery fixes this as there was a bug in one of the prior versions (jQuery 1.7.?) with the .ready() function which was documented in the release notes.

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

Sidebar

Related Questions

Sometimes on an R help page the phrase not run appears in comments. Check
Error I tried this page to run on local, it is running perfectly fine
i am useing the query below, when i run this query once per page
When I run my website,sometimes run without error and some times this exception accord.
Is it possible to run Ant's build.xml from PHP or a web page? Sometimes
I have a facebook app which run only through a fan page. Go to
I am using Struts application while running welcome page is run successfully after that
I have some code that I'd like to run on a page. My problem
I have a user control that is being integrated to the page on run
I run a php script on a page which looks for certain classes/elements and

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.