Does IE11 use a hash-table to optimize document.getElementById()?

Viewed 204

Does IE11 use a hash-table to optimize calls to document.getElementById() or if not, what kind of optimization is used? My logic is that document.getElementById() will be called fairly often and a full traversal of the DOM tree would be inefficient, so it would make sense to optimize it.

I am asking about a specific browser and a specific method in order for my question to be answerable.

1 Answers

I think it does. Please check this beautiful article describing the internals of browers. Now to verify this in IE11, if you examine the window object, you'll see a the controls referenced by id. For example, instead of directly doing a

var control = document.getElementById("#id")

you can directly do a

var control = window["id"] 

and get a reference to the element.

Related