简体   繁体   English

$('。classname')和$ .find('。classname')之间有什么区别

[英]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.

相关问题 javascript中class和classname有什么区别? - What is the difference between class and classname in javascript? className={&#39;container&#39;} 和 className=&#39;container&#39; 有什么区别 - What is the difference of className={'container'} with className='container' 关于CSS继承,class和className有什么区别? - What's the difference between class and className with respect to css inheritance? HTML 中的 button#classname 和 button.classname 之间有区别吗 - Is there a difference between a button#classname and a button.classname in HTML $(&#39;。className&gt; button&#39;)和$(&#39;。className&#39;)。children(&#39;button&#39;)之间有什么区别吗? - Is there any difference between $('.className > button') and $('.className').children('button')? $ .children()与$ .children(&#39;className&#39;)有什么区别? - $.children() vs $.children('className') What's difference? x = document.getElementById(“ id”)。className =&x = document.getElementById(“ id”),x.className =之间的区别 - Difference between x = document.getElementById(“id”).className = & x = document.getElementById(“id”), x.className = 按类名查找元素 - find elements by classname 通过classname的一部分查找类 - Find a class by a part of classname (this).parent()。find(&#39;。classname&#39;)不起作用 - (this).parent().find('.classname') not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM