r/JavaScriptTips • u/Head-Investment-1549 • 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
1
3
u/zapembarcodes Jul 12 '23
As far as I'm concerned the difference is negligible.
I mostly stick with querySelector()