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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:54:53+00:00 2026-05-11T17:54:53+00:00

I don’t know if this is a well known ‘thing’ or something new in

  • 0

I don’t know if this is a well known ‘thing’ or something new in whatever version of Firefox it just updated itself too – but in either case I have no idea how to google for this question so I’ll have to ask it here.

I have a DIV in my DOM that I am trying to directly access by id, in the most simplest form like this:

 alert(btnTest.id);

This works fine in all browsers, but was causing issues in firefox that actually led to the browser being in a strange ‘broken’ state.

The error I was getting was ‘btnTest is not defined’. I did not get this error in Safari, Internet Explorer or Chrome.

I assumed I had mismatched HTML tags, or javascript curly braces or something else missing. Eventually after stripping everything out I tried removing the DOCTYPE. Suddenly in Firefox (v 3.0.10) it started returning the correct ID as expected.

What is going on!!! ?? Surely ‘strict’ mode should allow me to access named elements, and if not then why do all the other browsers let me.

Note: I can easily work around it with $(‘#btnTest’)[0].id, which is what I’m going to have to do now until i can figure out a better solution.

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" class="blueCircles">

 <head>

    <script type="text/javascript"
            src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

    <script>
        $(function() {
            alert("ID retrieved through jQuery: " + $('#btnTest')[0].id);
            alert("ID retrieved by accessing global variable: " + btnTest.id);
        });

    </script>

</head>
<body>
    <div id="btnTest">
    </div>
</body>
</html>
  • 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-11T17:54:54+00:00Added an answer on May 11, 2026 at 5:54 pm

    There is nothing in any W3C specification that says object references should be established in the global scripting scope for elements with id attributes. This is considered to uneccessarily pollute the global namespace and can result in confusing errors.

    Firefox establishes the references when running in quirks mode for the purposes of IE compatibility. Johnny Stenback explains in the third comment on the bug for adding this support why this isn’t supported in standards mode:

    This feature does affect standard
    compliant code that for instance
    checks for the existance [sic] of a global
    variable to set it only once. With
    this change, that “varible” [sic] may now be
    a reference to an element in the
    document, and the code may not work
    the way the developer intended.

    That’s the reason we decided to make
    this quirks only.

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

Sidebar

Related Questions

I don't know why, but this code worked for me a month ago... maybe
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
I don't know: if this works. if it's a good idea. what it is
I don't know if this question is trivial or not. But after a couple
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't know a whole lot about streams. Why does the first version work using
Don't know if this is the right place to ask this, but I will
Don't know why this is happening, but after submitting a form via JS (using

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.