Message from JavaScript discussions

September 2018

— And THEN it executes what it parsed


But still htmlcollection updates itself when any dom node with the corresponding classname gets added later on. Maybe elementsByClassName is initially faster but I still think queryselctorall is overall faster. And when you just use querySelectorAll(".foo") instead of getElementsByClassName("foo") it shouldnt be a real performance difference. In the jsperf test it was supposed to be way faster.

— It doesnt matter what both return, as you said about function speed not result usage speed

— Create a test, lets see

— Https://

— Not very isolated comparison, but.. shows

— The main benefit of querySelectorAll is that it follows CSS specificity rules

— If you see that, you'll know getElementsByClassName has enough perf benefit to prefer it when:
1. You know you're only going to lookup based on class name
2. You're doing many such operations

Message permanent page

— QuerySelector is good when:
1. You need the flexibility of CSS selectors
2. You're only doing a handful of tasks and performance wouldn't be a bottleneck

Message permanent page

— Or you are not going to use css specificity🤤

— Ye. world will not crush

— What