Recently I found jquery's filter () method. This is a very powerful method. The most powerful thing is that it can accept a function as a parameter and then judge it based on the return value of the function, if the returned value is true, this element will be retained. If the returned value is false, this element will be removed and recently discovered by 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.
Hello, how old are you today?
Why?
If we want to select a child element
This is what I usually write.
$ ("P> span"). parent ();
Now we can use. filter () to write it like this:
$ ("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.