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

Learn more about the difference between filter() and find() in jQuery_jquery

WBOY
Release: 2016-05-16 17:21:25
Original
1217 people have browsed it

I have never been very clear about the difference between the filter() method and the find() method. Today I finally figured it out after reading the jQuery Cookbook.

filter() filters the DOM element packaging set, which refers to operating the current element set, deleting unmatched elements, and obtaining a new set

Copy code The code is as follows:

$('div').filter('.div1');//Select the div element with the class attribute of div1 in the div tag

find() finds qualified descendants in the context of the currently selected element, and returns the child element
Copy code The code is as follows:

$('div').find('em');//Select the element of the em tag in the div tag

As can be seen from the above, filter() operates on the selected element set to obtain the qualified elements among these elements, while find() obtains the qualified descendant sub-elements of the selected element

.

Finally, introduce an end() method to return the selection before destructive modification
Copy code The code is as follows:

$('div').filter('.div1').end();//What is returned is the selected element before using filter(), that is, $('div ')
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!