The filter function allows you to filter the qualified DOM elements from the wrapper set.
If we have an HTML file that reads as follows, to get the <a> elements of the class as external, using filter can be easy to handle.
Copy Code code as follows:
<a href= "#" class= "external" >link</a>
<a href= "#" class= "external" >link</a>
<a href= "#" >link</a>
<a href= "#" class= "external" >link</a>
<a href= "#" class= "external" >link</a>
<a href= "#" ></a>
<a href= "#" >link</a>
<a href= "#" >link</a>
<a href= "#" >link</a>
<a href= "#" >link</a>
The parameter types of filter can be divided into two kinds:
1 Pass Selector
2 Transfer Filter function
If you use a selector as a parameter, the following
Copy Code code as follows:
$ (' a '). Filter ('. External ')
Using Anonymous filter functions
Copy Code code as follows:
$ (' a '). Filter (function (index) {
return $ (this). Hasclass (' external ');
})
The index of the argument is the subscript of the result set.