Adrian
Adrian

Reputation: 3062

Which has better performance jQuery class selector or document.querySelectorAll?

I am trying to aim not to use jQuery and just rely on JavaScript/ES6 codes. I think selecting elements can be achievable by using JavaScript's document.queryselectorAll and assign it to a variable.

Do you have any idea if there is a performance difference between jquery class selector vs document.queryselectorAll?

For example: $(".list-wrap .list-item") vs var elementSelector = document.querySelectorAll(".list-wrap .list-item")

I am also trying to find out that if I can do it purely in javascript without using jQuery it is faster because I am not using an additional library.

Any help is greatly appreciated. Thank you.

Upvotes: 2

Views: 518

Answers (1)

keul
keul

Reputation: 7819

If you are using selection query compatible to querySelectorAll you'll get the same performance.

jQuery is a smart and well designed library: it uses querySelectorAll internally if it's available in the browser.

https://github.com/jquery/jquery/search?q=querySelectorAll&unscoped_q=querySelectorAll

Upvotes: 5

Related Questions