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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:02:33+00:00 2026-06-12T22:02:33+00:00

Possible Duplicate: IE/Chrome: are DOM tree elements global variables here? I am currently working

  • 0

Possible Duplicate:
IE/Chrome: are DOM tree elements global variables here?

I am currently working on a mobile site using jquery mobile and I noticed something interesting (to me anyway, as I am still new to js). Inside a function, you can reference an element with just the id.

This is the test code I used (on chrome 22.0.x, firefox 16.0.1, and safari 5.1.7):

<!DOCTYPE html>
<html>
  <head></head>
  <body onload="tt()">
    <div id="abc">Test</div>
    <a id="cba">Test2</a>
  </body>
  <Script>
    function tt() {
        console.log(abc);
        abc.style.backgroundColor = "red";
        return cba;
    }
  </Script>
</html>

No getElementById, no jquery selector, just the id. Has it always been this way? If so, is this a good practice and why does this work? I am thinking function must have a context, but where is it, is it the page?

Any insight would be appreciated, 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-06-12T22:02:34+00:00Added an answer on June 12, 2026 at 10:02 pm

    You are really doing:

    window.abc;
    

    This is something that IE started that was really a poor design choice.

    See this great answer to a very very similar question

    It’s really a duplicate but the title does not reflect this.

    Try this line in your console to see what I mean.

    (function(){ console.log(this); })(); // logs the Window object
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: IE/Chrome: are DOM tree elements global variables here? I just stumbled upon
Possible Duplicate: How do I stop Chrome from yellowing my site’s input boxes? I've
Possible Duplicate: How do I stop Chrome from yellowing my site's input boxes? i
Possible Duplicate: css @font-face not working with firefox, but working with chrome and IE
Possible Duplicate: What makes a jQuery object show up as an array in Chrome's
Possible Duplicate: Javascript: How to loop through ALL DOM elements on a page? var
Possible Duplicate: jQuery .load method not firing on IE9 Hi I'm using a simple
Possible Duplicate: How to parseInt a string with leading 0 I'm using Google Chrome
Possible Duplicate: How to add google chrome omnibox-search support for your site? I have
Possible Duplicate: CSS3 transition of background-image for Firefox not working first post here. I've

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.