What's the difference between $ ('. Classname') and $ .find ('. Classname')

Sometimes $('.classname')

they $.find('.classname')

give different results. I wonder what is the difference between them.


source to share

3 answers



will search the DOM for elements with a class classname




will give you the error of doing nothing, why

.find (selector)

the string selectorA containing the selector expression to match elements against. version added: 1.6.

.find (jQuery object) A jQuery objectJQuery to map elements. Added version: 1.6

.find (element) elementAn to match elements with.



I can not tell you,

but you can see the source code for $. find and $. fn.find


This is a technique used by jQuery itself and is not recommended for use as a query selector.


Refers to $.find

in the main structure: (where this

is a jQuery object)

var ret = this.pushStack("", "find", selector),
    length, n, r;

for (i = 0, l = this.length; i < l; i++) {
    length = ret.length;
    jQuery.find(selector, this[i], ret);






will return a list of all the elements with that class name in the document so that they can be iterated over with .each()



searches the dom tree and returns class events. But you will need to provide a parent, for example:




All Articles