getElementById can be considered O(1) in a modern browser because the hash table is an ideal data structure for displaying id => elements.
Without any optimizations, any simple query - be it a css selector, identifier search, class or tag name search - is no worse than O(n) , since one iteration over all elements is always enough.
However, in a good browser, I expect it to have a tag element mapping =>, so getElementsByTagName will also be O(1) .
Thiefmaster
source share