Click to See Complete Forum and Search --> : getting element by id


chuvak
06-26-2003, 01:26 PM
Hi,

does getElementById(...) sequentially go through all the ID's on the page to find the element?
How are the ID's stored? Is it only array of the elements that have explicitly defined id="..." or something else?
Is it much faster to give id's to all of the element's parents and then get element by document.parent1.parent2....parentN.ID?
Of course going through 100 or 1000 elements is very fast on computers nowadays, but on an embedded device (which is the issue in my case) it might make a difference.

Also can someone point me to a good reference on the DOM?

thanks in advance

Jona
06-26-2003, 08:01 PM
document.getElementById('id') returns the object with that explicit ID. However, if you'd like to return an array of elements of the same type, you may use document.getElementsByTagName("tagName")[x] where "x" can be any number. This references an object individually, but can be used with a for() loop to extract each element at a time.
Here are three references to the DOM:
http://devedge.netscape.com/
http://www.w3.org/DOM/
http://msdn.microsoft.com/library/

[Jona]