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.
- How to design filter widget for mobiles using jQuery plugin ?
- Underscore.js | _.filter() with Examples
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- p5.js | filter() Function
- TypeScript | Array filter() Method
- HTML DOM NodeIterator filter property
- HTML DOM TreeWalker filter Property
- D3.js selection.filter() Function
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.