+ 3

What is faster - querySelector or getElementById?

5th Nov 2018, 11:01 AM
Дмитрий Эдуардович Филиппенко
Дмитрий Эдуардович Филиппенко - avatar
5 odpowiedzi
+ 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