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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:54:21+00:00 2026-06-03T03:54:21+00:00

I noticed while playing around with Chrome that both of these functions work the

  • 0

I noticed while playing around with Chrome that both of these functions work the same:

<img src="picture.jpg" id="myelement" />

function stuff(){
var x=document.getElementById("myelement");
x.style.display="none";
}//works almost everywhere

function stuff(){
myelement.style.display="none";
}//only works in Chrome

Why does Chrome allow me access the element straight from the id without using ‘getElementById’?
And is it bad practice to do it this way?
Does it hurt performance?

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-03T03:54:22+00:00Added an answer on June 3, 2026 at 3:54 am

    Chrome automatically creates global variables corresponding to each element with an id. It is a very bad idea to use these variables in production code because no variables are static in javascript – somebody could have later assigned something else to myelement and you would have no way of knowing.

    If you do use this feature (presumably in a testing environment, like the console), I would guess it is faster than getElementById(), as the code to assign myelement to the corresponding node is run first either way.

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

Sidebar

Related Questions

While playing around with the emulator, I noticed that when trying to view a
While playing around with some hooks I noticed that the output from the hooks
I've noticed, while playing around with it, that if you scroll up and down
I noticed that many times while developing for an iPhone 3G, BSD socket functions
While playing around with playframework yabe-siena-gae, I noticed a datastore file created for the
So I've been playing around with web development and I've noticed that in Firefox,
I've been playing around with the windows clipboard. I noticed that you can only
I was playing around with this code. http://programmersvoice.com/tag/code And I noticed that the following
I noticed while making a program that a lot of my int type variables
While reading cocoa tutorials i've noticed that some of the tutorials use AppDelegate 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.