News for hackers. Stuff that matters.
Re:GetElementById vs. QuerySelector by esprehn on Friday November 26, 2021 @09:10AM (#29350294)
Browsers do exactly the optimization you're describing: https://source.chromium.org/chromium/chromium/src/+/main:thi...

Both getElementById and querySelector are quite fast, down to the level of measuring individual branches in a micro benchmark. querySelector does have to do a bit more work to lookup the cached query and a handful of extra branches over getElementById, it's not scanning the document for an ID query unless you're in quirks mode though.

There are no comments on this comment yet.