What is better to use for performance in JavaScript?
document.children[0].children[1]
vs
document.querySelector('body')
Which is more faster in performance?
What is better to use for performance in JavaScript?
document.children[0].children[1]
vs
document.querySelector('body')
Which is more faster in performance?
Here you've the result from fast to slow:
document.body (by far)document.querySelector('body'), document.children[0].children[1], document.getElementsByTagName('body')[0] (about the same)document.querySelectorAll("body")[0], $('body')Source JSBench (try it yourself)