[英]what is difference between $('.classname') and $.find('.classname')
Sometimes $('.classname')
and $.find('.classname')
gives different result. 有时$('.classname')
和$.find('.classname')
给出不同的结果。 Wondering what is the difference between both. 想知道两者之间有什么区别。
$('.classname')
will search the DOM for elements with class classname
and 将在DOM中搜索具有类classname
和的元素
$.find('.classname')
will give you error do nothing, why 会给你错误什么都不做, 为什么
.find( selector ) .find(选择器)
selectorA string containing a selector expression to match elements against. selector包含用于匹配元素的选择器表达式的字符串。 version added: 1.6. 版本新增:1.6。
.find( jQuery object ) jQuery objectA jQuery object to match elements against. .find(jQuery object)jQuery object一个jQuery对象,用于匹配元素。 version added: 1.6 版本新增:1.6
.find( element ) elementAn element to match elements against. .find(element)elementAn要匹配元素的元素。
I can't tell you, 我不能告诉你,
but you can see the source-code for $.find and for $.fn.find 但你可以看到$ .find和$ .fn.find的源代码
$.find
: $.find
:
It's a method used by jQuery itself and not recomented to use as query selector. 这是jQuery本身使用的一种方法,并没有被推荐用作查询选择器。
$.fn.find
: $.fn.find
:
Refers to $.find
in the core framework: (where this
is a jQuery Object) 引用核心框架中的$.find
:( this
是一个jQuery对象)
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);
...
$('.classname')
will return a list of all of the elements with that classname in the document so they can be iterated with .each()
. $('.classname')
将返回文档中具有.each()
的所有元素的列表,以便可以使用.each()
进行迭代。
$.find('.classname')
searches the dom tree and returns occurances of the class. $.find('.classname')
搜索dom树并返回该类的出现。 But you would have to supply a parent element, eg: 但是你必须提供一个父元素,例如:
$(document).find('.classname')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.