From the jquery filter. Filter () method thought of _jquery

Source: Internet
Author: User
Recently discovered jquery's. Filter () method, which is a very powerful method, the most powerful is that he can accept a function as a parameter, and then based on the return value of the function to determine if the return value is true, this element will be retained, if the return value is false, This element will be removed. This is the jquery selector filter.

Empty say useless, let's show
Copy Code code as follows:

<body>
<p> Hello, how old are you today </p>
<p><span> why to tell you </span></p>
</body>

If we're going to choose a <p> element that has a <span> element, that's what I usually write.
Copy Code code as follows:

$ ("P>span"). Parent ();

Now with the help of. Filter () We can write this way:
Copy Code code as follows:

$ ("P"). Filter (function (index) {
Return $ (a). FIND ("span"). Size ();
});

Although it may seem like a bit of a hassle, he provides us with a very powerful custom lookup element, we can pass a function and then use the implicit iteration of jquery to find it.

This is the most flexible way to find elements that I see in jquery today.

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.