. 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.