Is there a difference in $ (document) .find ('selector') and $ ('selector')

I started working on some project, and in the code I find combinations of $ (document) .find ('selector') and $ ('selector'). I can not find the real reason why this is done. Am I there some significant differsece between these two, so that they are used simultaneously in the project? if i prefer one over the other in some cases?

+6
source share
3 answers

$(document).find("selector") and $("selector") will correspond to the same set of elements.

There is no reason to use $(document).find(...) for $(...) and several reasons not:

enter image description here

+7
source

They are functionally equivalent. There is no difference in behavior between $("selector") , $(document).find("selector") and $("selector", document) .

In terms of performance, some options may be slightly slower than others (since these methods are implemented in terms of others). This, however, is implementation detail and can be changed between releases. Benchmarking a specific release will be for sure.

+3
source

$(document).find(selector) and $(selector) both look for a selector in the document.

+1
source

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


All Articles