Performance: Selector or Move?

I was wondering what was the fastest way to apply the class on the body and let's say all paragraphs. We can use simple selectors like:

$("body").addClass("foo");
$("p").addClass("bar");

      

But also move methods such as:

$("body").addClass("foo").find("p").addClass("bar");

      

Is there a difference in the deadline?

Cheers, Benjamin

+2


source to share


1 answer


I suspect the second version will be slightly faster because it find

will look for elements that match the selector among the children of the previous selector results. However, in this case, the difference is likely to be so small that you won't even notice it.



+3


source







All Articles