Think of the _ jquery from the jquery filter. filter () method

Source: Internet
Author: User
. The filter () method can take a function as a parameter and judge based on the return value of the function. This is the filter of the jquery selector. Below is a good example, you can refer to the recently discovered jquery. the filter () method is really a very powerful method. The most powerful thing is that it can take a function as a parameter and then judge based on the return value of the function. If the return value is true, this element will be retained. If the returned value is false, this element will be removed. This is the filter of the jquery selector.

It's useless. Let's show it.

The Code is as follows:



Hello, how old are you today?


Why?




If we want to select a child element

This is what I usually write.

The Code is as follows:


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


Now we can use. filter () to write it like this:

The Code is as follows:


$ ("P"). filter (function (index ){
Return $ (this). find ("span"). size ();
});


Although it seems a little troublesome, it provides an extremely powerful feature for Custom Search elements. We can pass a function and use jquery's implicit iteration to implement search.

This is the most flexible method for searching elements that I have seen in jquery.
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.