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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:31:17+00:00 2026-05-22T18:31:17+00:00

HI Guys, I have a question, Im trying fo find the most efficient way

  • 0

HI Guys, I have a question,

Im trying fo find the most efficient way in terms of performance to store and access an element in the javascript protoype library.

lets say I dynamically create a parent with an child element in a test class

testclass = Class.create({

   newParent: null, //I will create a global reference to the parent element

   method1: function(){
      this.newParent = new Element('div',{'id':'newParent'});
      var elm = new Element('div',
      {
         'id': 'elm1',
         'identifier': 'elm1identifier'
      }
      );

      newParent.insert(elm);
   },

    method2: function(){
       ??????????
    }

})

In method 2, I want to be able to access the element elm1.

I have been thinking, and here are my different solution.

  1. I can access the element using the utility method provided by prototype $()

    method2: function(){
       $('elm1');
    }  
    
  2. I can make a global reference to the element.

    elm1: null,
    ....
    method2: function(){
      this.elm1
    }
    

3.I can pass the element in the method as a parameter but this option will not always be available

  1. I create a unique identifier as an attribute and use the protoype .down function

    this.newParent.down('[identifier=elm1identifier]');
    

So ofcourse i use a combination of these, but im curious, at out of all the methods, which is the most efficient in terms of performance.

I heard that the $() utility method searches the whole dom? Is this a significant difference? What if you have alot of elements.

Storing references to elements may also cause memory problems especially if you have a lot of javascript in a big web site.

using a unique and custom identifier is also nice, but you also add new attributes which might have an effect on the dom itself. But this advantage is that you specifiy where you want to search using the element.down() method in prototype.

Thanks for the help guys.

  • 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-22T18:31:17+00:00Added an answer on May 22, 2026 at 6:31 pm

    If you are creating an object that is supposed to represent a DOM element, it seems sensible to give it a property that references the element, say “element”. Then in method1:

    this.element = elm;
    

    I think at this stage, micro-optimising for performance is pointless since the biggest improvement in performance would be to not use Prototype.js.

    The $() method is firstly an alias for document.getElementById (which is blazingly fast in browsers and always has been) and secondly adds convenience methods to the element returned. If the browser doesn’t implement a prototype based inheritance scheme, Prototpye.js adds about 50 methods directly to the element as properties, which is a pretty expensive operation.

    I doubt that storing references to elements will cause significant memory issues unless you are storing tens of thousands and not using them (they are just references after all).

    using a unique and custom identifier
    is also nice, but you also add new
    attributes which might have an effect
    on the dom itself

    Do not add custom attributes or properties to DOM elements. Prototype.js version 2.0 is going away from this model (at last), just don’t do it. If you have an object that represents (or “wraps”) an element, add the property to that.

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

Sidebar

Related Questions

So I have a question for you guys... I am trying to write a
i have a question for you guys. im trying to print an array where
I Am trying to learn the RDBMS. I have question for you guys. Why
guys I have two question to ask, they're easy, but bothering me for a
Hey guys i have a question which i have been looking for the answer
Hi guys I have a weird question, I have a cli php script runs
Hi guys I have an easy question, but not easy to me. I have
Hey guys I have one more question lol. I am using a script that
Hey guys I have what should be a simple question, but I am new
Hey guys quick question, I have an entry that I put in my database,

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.