jQuery filter() method

Last Updated Jul 14, 2015, 05:50:00 AM





jQuery filter() method

The jQuery filter() method returns elements that match a certain criteria..

The criteria can be given as a selector, argument to filter() method. Please note that the filter() method in jQuery is completely different function of not() method.

Syntax

Consider a web page with with 5 div elements, each one has class whose name is middle. The jquery filter() method gets all elements which matches the class name value as middle. Finally, you can manipulate the elements with css styles.


Example

It will filter all the paragraphs which contain it's class name as "bad" and applies the green color background to it

It will filter all the paragraphs which contain it's class name as "good" and applies the yellow color background to it


Output
jquery filter() method
Try It Now

Other Advanced jQuery Traversing Methods you might want to learn
jQuery Traversal Reference

jQuery Basic Traversing

jQuery Traversal Filters

jQuery Traversing Methods

Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 14, 2015, 05:50:00 AM