Example of jQuery basic knowledge filter () and find () _ jquery

Source: Internet
Author: User
This is a commonly used method in jQuery. Their two functions are completely different, and beginners are often misled. First, let's look at the. find () method:
There is a page in which the HTML code is;

The Code is as follows:



Test 1




Test 2




If we use the find () method:
Var $ find = $ ("p"). find (". rain ");
Alert (LOGIN find.html ());
The output is as follows:


If the filter () method is used:
Var $ filter = $ ("p"). filter (". rain ");
Alert (export filter.html ());
The output is as follows:

Maybe you have seen the difference between them.
Find () searches for elements whose class is rain in the p element.
Filter () is the element that filters p's class as rain.
One is to operate on its subset, and the other is to filter its own set elements.

In addition, find () can also be represented by selector:
Var $ select = $ ("p. rain ");

Do you understand their differences?
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.