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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:16:52+00:00 2026-06-11T22:16:52+00:00

I often use the method getElementById(id1); in my methods. I use it to find

  • 0

I often use the method getElementById("id1"); in my methods. I use it to find certain elements in my HTML. I wonder if I need to be concerned about how much I use it if it has to search the entire DOM every time.

How does this method work? Does it parse the DOM and return the element when it is found, or does it have all those values indexed somehow and so is able to return more quickly?

P.S. I am curious about the method in general, but I am using an Android WebView if that makes any difference.

  • 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-11T22:16:53+00:00Added an answer on June 11, 2026 at 10:16 pm

    getElementById is very fast and you shouldn’t have to worry about performance.

    If you are using the same ID over and over (and over and over) again, you might want to cache it. The performance gain is neglectable:

    var myId = getElementById("myId");
    myId.operation1();
    myId.operation2();
    myId.andSome5000MoreCalls();
    

    Check this SO answer for some benchmarks.
    The results Mike posted were:

    IE8 getElementById: 0.4844 ms
    IE8 id array lookup: 0.0062 ms

    Chrome getElementById: 0.0039 ms
    Chrome id array lookup: 0.0006 ms

    Firefox 3.5 was comparable to chrome.

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

Sidebar

Related Questions

I have created a View controller with some methods I need to use often
How often should I use static methods generally? If I have like: Class1 _class34
Often we have to use some of the methods which don't return anything useful.
OK. I'm not completely clear about blocks, but I do use them often; especially
So a method I often use to create nice SEO links that use images
In my Java code I often use the very handy method(Class... args) varargs. As
I often get into situation when I'd like to use template method pattern, but
I often use JFrames, and because they are applications, they obviously need a public
I'm looking for a method to see how often people use my application and
I often use a framework that allow you to inherit from a certain class,

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.