I am creating one of my first web applications using HTML5, in particular for the iPhone.
Since I'm fairly new to this, I am trying to develop some good coding habits, follow best practices, optimize performance and minimize the load on iPhone with limited resources.
One of the things I need to do often ... I have a lot of divs (each of which has a unique identifier) ββthat I often update (for example, using innerHTML) or change (for example, style attributes with webkit transitions and transformations) .
In general - should I use getElementByID every time I need a div descriptor, or do I need to store references to every div that I refer to in the "global" variables at the beginning?
(I use the "global" in quotation marks because I really only have one really global variable - this is an object that stores all my "global" variables as properties).
I assume that using getElementByID each time should have some overhead since the function must traverse the DOM to find the div. But, I'm not sure how the taxation or effectiveness of this function.
Using global variables to store descriptors for each element should consume some memory, but I donβt know if this link just requires a trivial amount of RAM or more.
So - which is better? Or, both options consume such a trivial amount of resources that I should only worry about, which creates more readable, supported code?
Thank you very much in advance!
javascript html5
mattstuehler
source share