The jQuery is a very powerful tool which helps us to incorporate a variety of DOM traversal methods to select elements in a document randomly or in sequential order. Most of the DOM traversal methods do not modify the elements whereas they filter them out upon the given conditions.
The filter() method is used to filter out all the elements that do not match the selected criteria and those matches will be returned.
criteria : It specifies a selector expression, a jQuery object or one or more elements to be returned from a group of selected elements.
function(index) : It specifies a function to run for each element in the set. If the function returns true, the element is kept. Otherwise, it is removed.
index : The index position of the element in the set.
NOTE : To specify more than one criteria, use a comma.
This code will return all elements matching with selected criteria.
This code will select the elements matching with the criteria checked by the function. Here, the function checks for two elements in a list and returns true or false.
- Underscore.js | _.filter() with Examples
- jQuery | eq() with Examples
- jQuery | first() with Examples
- jQuery | one() with Examples
- jQuery | last() with Examples
- jQuery | on() with Examples
- jQuery | after() with Examples
- jQuery | val() with Examples
- jQuery | has() with Examples
- jQuery | change() with Examples
- jQuery | not() method with Examples
- jQuery | wrapAll() with Examples
- jQuery | prop() with Examples
- jQuery | slideUp() with Examples
- jQuery | mousemove() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.