JQuery filter function use method


The filter function is used to filter qualified DOM elements from the wrapper set.

If we have an HTML file with the following content, get the < for the external class; A> Element, which you can easily do with a filter.


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

Filter parameter types can be divided into two types:

1 pass the selector

Pass the filter function

If you use a selector as an argument, the usage is as follows


$('a').filter('.external')

Use anonymous filtering functions


$('a').filter(function(index) {
return $(this).hasClass('external');
})

The parameter index is the index of the result set.