What is faster - querySelector or getElementById? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

What is faster - querySelector or getElementById?

5th Nov 2018, 11:01 AM
Š”Š¼ŠøтрŠøŠ¹ Š­Š“уŠ°Ń€Š“Š¾Š²Šøч Š¤ŠøŠ»ŠøŠæŠæŠµŠ½ŠŗŠ¾
Š”Š¼ŠøтрŠøŠ¹ Š­Š“уŠ°Ń€Š“Š¾Š²Šøч Š¤ŠøŠ»ŠøŠæŠæŠµŠ½ŠŗŠ¾ - avatar
5 Respostas
+ 9
getElementById probably because it doesnt do any additional operations such as analysing your input.
5th Nov 2018, 11:09 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Try this to test the speed of each update functions, notice the speed of jQuery function. https://code.sololearn.com/Wu20kv75u57T/?ref=app
8th Nov 2018, 8:58 AM
CalviÕ²
CalviÕ² - avatar
+ 2
get ElementById- gets an element with particular I'd ,in this case it will be operable to all same ID's . querySelector- it is operable for the first occurance of a id
5th Nov 2018, 1:12 PM
Adarsh.n. Bidari
Adarsh.n. Bidari - avatar
+ 2
I think, querySelector is faster
6th Nov 2018, 1:55 PM
xphnx
xphnx - avatar
+ 1
getElementById is faster but no significant. So we use whichever that convenient to us most.
5th Nov 2018, 12:27 PM
CalviÕ²
CalviÕ² - avatar