Which is faster when using jquery.classname or div.classname selectors

Is it faster to use

$(".classname").

or add a tag to search also

$("div.classname")

I think this is the name of the class, since I'm sure jquery will just loop around to get all the class names, where the second will get all the div tags first and then quote this subset to get the cool names. Here is what I think anyway.

Somebody knows?

+4
source share
1 answer

You can always run your code on jsperf.com to check the performance of the code sequence in different browsers.

. Chrome , ( + ) ,

enter image description here

, .

https://jsperf.com/jquery-class-vs-tag-qualfied-class-selector/2

+4

Source: https://habr.com/ru/post/1665607/


All Articles