document.images returns a collection of the images in the current HTML document. Well, I assumed that it could be faster to get image reference by using document.images collection than just document.getElementById because document.images not operating on as large an HTMLCollection.

However, I made some test (on jsperf as well) and seems that document.getElementById method is faster in Firefox 22 and Chrome 27.0.1453.116 m, but not in IE 10.0.9200.16618 and not in Opera 12.15. All tests was done on Windows 7, 64bit.


As suggested by [HTML 4.01], to include images, authors may use the OBJECT element or the IMG element. Therefore, it is recommended not to use this attribute to find the images in the document but getElementsByTagName with HTML 4.01 or getElementsByTagNameNS with XHTML 1.0.

However, from my point of view if there is no impact on performance then I think that getting reference to image by document.images collection is better because document.images is more precise and self-descriptive.


You can leave a response, or trackback from your own site.

Before you add comment see for rules.

Leave a Reply

Your email address will not be published. Required fields are marked *