Home > Web Front-end > JS Tutorial > jQuery basic knowledge filter() and find() examples_jquery

jQuery basic knowledge filter() and find() examples_jquery

WBOY
Release: 2016-05-16 18:23:32
Original
999 people have browsed it

First, let’s look at the .find() method:
Now there is a page with the HTML code: :

Test 2


If we use the find() method:
var $find = $("div").find(".rain");
alert( $find.html() ) ;
will output:


If you use the filter() method:
var $filter = $("div").filter(".rain");
alert( $filter.html() );
will be output :

jQuery basic knowledge filter() and find() examples_jqueryMaybe you have seen the difference between them.
find() will look for elements with class rain within the div element.
And filter() filters the elements whose class is rain in div.
One is to operate on its subset, and the other is to filter the elements of its own collection.

In addition, find() can actually be represented by a selector:
var $select = $("div .rain"); jQuery basic knowledge filter() and find() examples_jquery
Do you understand the difference between them?
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