Reduce the set of matched elements to those that match the selector or pass the function's test.
$('li').filter('.active').css('color', 'red');
// Only matching elements are modified
<li class="active" style="color: red;">...</li>
<li>...</li>
$('li').filter((index) => index % 2 === 0).addClass('even');
<li class="even">Item 0</li>
<li>Item 1</li>
<li class="even">Item 2</li>
| Parameter | Type | Description |
|---|---|---|
| selector | string | function | element | SR | A string containing a selector expression to match elements against, or a function to test each element, or an element/SR object to match. |
Returns: A new SR object containing the filtered elements.