Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere


The filter() method returns elements that match a certain criteria.
Elements that do not match the criteria are removed from the selection, and those that match the criteria will be returned.
This method is often used to narrow down the search for an element in a group of selected elements.
Syntax :$(selector).filter(criteria)
Here criteria is an optional parameter specifies a selector expression, a jQuery object or one or more elements to be returned from a group of selected elements.

Specify multiple criteria in filter method of Jquery To specify multiple criteria, seperate the criteria with comma.

Above code will return all the p element those have intro class.

2- $("p").filter(function(i)
return i == 2;
).css("background-color", "yellow");});
Here we are iterating through all the p elements and setting the background color to yellow.