Use the filter function to filter the qualified DOM elements from the wrapper set.
If we have an HTML file with the following content, to get the <a> elements of the class external, using filter can be easily done.
<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 Pass Filter function
If the selector is used as a parameter, use the following
$ (' a '). Filter ('. External ')
Using anonymous filtering functions
$ (' a '). Filter (function (index) {return $ (this). Hasclass (' external ');})
The parameter is the subscript index
for the result set.