QueryselectorAll Usage
I am currently using a JS library for my organizations and one thing I want to introduce is querySelectorAll.
Looking at compatibility, it will work in a modern browser, while for older browsers, I'll use feature detection:
if (document.querySelectorAll) {
var nodes = context.querySelectorAll(queryValue);
} else {
var nodes = context.getElementsByTagName(queryValue);
}
Are there any considerations I should be aware of when using this method or is it good for production?
All opinions are appreciated
source to share
The main difference between the two is as follows:
getElementsByTagName
... will return a "live list" and
querySelectorAll
... will not be.
Since this is apparently only for select by tag, I would probably choose qsa
, so you can have a live list if needed. I have a feeling it qsa
might be slower in some browsers too, but haven't tested it.
EDIT:
This benchmark shows a big performance difference between the two in Chrome 13.
source to share