Filter Matched Set .filter()

.filter()

e.g. $("div").filter(criteria) criteria: { selector: ".className", Function: function(index,element){...}, jQuery Object: $("selector"), DOM element: document.getElementById( "id" )}

$("selector").filter() selects elements out of the matched set that match filter criteria.

Example 1: $("div").filter("#someID") will first find all <div> then filter them using selector to find the one with id='someID'.
<div id='someID'>div-1</div>
<div class='someClass'>div-2</div>
<p>p-1</p>
<div>div-3</div>
<span>span-1</span>
Example 2: $("div").filter( function( index ) { return index < 2 } ) will first find all <div> then filter them using function to find the ones with index < 2 within the matched set.
<div id='someID'>div-1</div>  // index = 0 within matched set 
<div class='someClass'>div-2</div>  //index = 1 within matched set
<p>p-1</p>
<div>div-3</div> // index = 2 within matched set
<span>span-1</span>
Matched set is a set of elements matching selector. For example, in Example 2 matchted set is set of elements matching $("div") selector
<div id='someID'>div-1</div> //index = 0
<p>p-1</p>
<div class='someClass'>div-2</div> //index = 1
<p>p-2</p>
<div>div-3</div> //index = 2
<span>span-1</span>
Example 3: $("div").filter( document.getElementById( "someID" ) ) will first find all <div> then filter them using DOM element to find the ones that match DOM element with id='someID'.
<div id='someID'>div-1</div>
<div class='someClass'>div-2</div>
<p>p-1</p>
<div>div-3</div>
<span>span-1</span>
Example 4: $("div").filter( $(".someClass") ) will first find all <div> then filter them using jQuery Object to find the one that match jQuery Object with class='someClass'.
<div id='someID'>div-1</div>
<div class='someClass'>div-2</div>
<p>p-1</p>
<div>div-3</div>
<span>span-1</span>
jQuery traversing filtering .filter()