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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:43:11+00:00 2026-05-22T00:43:11+00:00

On a page, I have several elements on which I need to perform repetitive

  • 0

On a page, I have several elements on which I need to perform repetitive operations. To avoid traversing the DOM every time, I want to store a reference to all these elements in an array (or an object).

Each of these elements has an id.

What is the most efficient: store the ids in my array, or store the elements themselves?

If I store the ids, then every time I want to access the elements I need to call getElementById. If I store the elements themselves, then my feeling is that it requires more “effort” from the browser (although I have no idea how it works in practice, and would be interested to know more).

  • 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-22T00:43:11+00:00Added an answer on May 22, 2026 at 12:43 am

    Much, much more efficient to store the element reference rather than just the id, because as you said, you avoid the lookup when you go to do operations on it.

    The downside to storing the element reference is that you have a reference to the element (that’s the whole point), and so if you remove the element from the DOM, you have to be sure to also release your reference to it or it will remain in memory. If these elements always exist on your page and never get removed, that’s fine, though I would recommend an unload handler that releases all of your references to the elements just to be sure older versions of IE don’t do silly things like keep them around even after the user has left the page.

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

Sidebar

Related Questions

I have a page which has several <canvas> elements. I am passing the canvas
I have a web page which has three <div> elements: Right_bar contains several layouts
I have several input and option elements on my page, each (well almost) have
I have several <li> elements with different id's on ASP.NET page: <li id=li1 class=class1>
We have a page of search results which the user can hit in several
I have several jQuery-ui range sliders on a page which add and remove rows
I have several asp:panels on a webform page which is used together with an
I have a custom.js file in which I have several elements that have click
I have several content pages hanging off of one master page. I need to
Say I have several JavaScript includes in a page: <script type=text/javascript src=/js/script0.js></script> <script type=text/javascript

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.