开发者

queryselectorAll usage

I am currently upating my organisations custom JS library and one thing I am looking to introduce is querySelectorAll.

Looking at compatibility it will run in modern browser and for older browsers I wi开发者_开发知识库ll use feature detection:

if (document.querySelectorAll) {
            var nodes = context.querySelectorAll(queryValue);
} else {
    var nodes = context.getElementsByTagName(queryValue);
}

Are there any considerations that I should be aware of when using this method or is it good for production?

All opinions valued


Main difference between the two is that:

getElementsByTagName

...will return a "live list", and

querySelectorAll

...will not.

Since this seems to be only for selection by tag, I'd probably ditch the qsa, so you can have the live list if needed. I've got a feeling that qsa may be slower in some browsers as well, but haven't tested it.


EDIT:

This test shows a big performance difference between the two in Chrome 13.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜