r/JavaScriptTips • • Jul 12 '23

querySelector() vs getElementById(). In performance, have any differences?

I suppose to querySelector() is more slowly than getElementById(), because doesn't search just an id, but, search all elements of DOM. Then, getElementById() have less options, therefore, is fastest.

Help me with the answer please, my self peace depends of this.

1 Upvotes

3 comments sorted by

3

u/zapembarcodes Jul 12 '23

As far as I'm concerned the difference is negligible.

I mostly stick with querySelector()

1

u/thekeym4ster May 18 '24

i am assuming you are right for the reasons you mentioned