Re: What's faster, saving an HTML DOM node as a variable, or using getElementById?



Hi,

ctman770@xxxxxxxxx wrote:
Hi Everyone,

Is it faster to save the precise location of an html dom node into a
variable in js, or to use getElementById everytime you need to access
the node?

I want to make my application as fast as possible. I have about 10-20
id tags that need to be accessed and modified from time to time. Would
the jvm perform slowly if I stored all of the dom node strings
"document.node.child...." into a huge js array?

Alternatively, would it also be slow if I had to use getElementById()
everytime I needed to access the node?

Thanks in advance for the help,
C

Just wanted to add that for big documents and multiple DOM Level 2 accesses to the document, document.getElementById presents huge performance problems. We found out that it's much, much faster to get one node and then to use navigation (through properties like firstChild, the children collection, nextSibling, etc...) to get to the nodes you want to modify. I am talking 10 times faster or more.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
.



Relevant Pages