Home > Web Front-end > JS Tutorial > body text

jQuery beginners: analysis of the difference between find() method and children method_jquery

WBOY
Release: 2016-05-16 18:11:05
Original
1286 people have browsed it

First, let’s take a look at the English explanation:
children method:
jQuery beginners: analysis of the difference between find() method and children method_jquery
find method:
jQuery beginners: analysis of the difference between find() method and children method_jquery
Through the above explanation, it can be summarized as follows:
1: children and Both find methods are used to obtain the subelements of element. Neither of them returns a text node, just like most jQuery methods.
2: The children method only obtains the child elements below the element, namely: immediate children.
3: The find method obtains all subordinate elements, that is: descendants of these elements in the DOM tree
4: The parameter selector of the children method is optional (optionally), used to filter child elements, but the find method The parameter selector method is required.
5: The find method can actually be implemented by using jQuery(selector, context): English says: Selector context is implemented with the .find() method; therefore, $('li.item-ii'). find('li') is equivalent to $('li', 'li.item-ii').

For example, there is the following html element:
jQuery beginners: analysis of the difference between find() method and children method_jquery
Use: $( 'ul.level-2').children().css('border', '1px solid green'); The effect is:
jQuery beginners: analysis of the difference between find() method and children method_jquery
Use $('ul.level-2') .find('li').css('border', '1px solid green'); The effect is:
jQuery beginners: analysis of the difference between find() method and children method_jquery

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template