Easy Tutorial
❮ Event Delegate Misc Callbacks Fire ❯

jQuery filter() Method

jQuery Traversal Methods

Example

Returns all <p> elements with the class name "intro":


Definition and Usage

The filter() method returns elements that meet certain conditions.

This method allows you to specify a condition. Elements that do not meet the condition are removed from the selection, while those that do meet the condition are returned.

This method is typically used to narrow down the scope of element search within a selected element group.

Tip: The filter() method is the opposite of the not() method.


Syntax

Parameter Description
criteria Optional. Specifies the selector expression, jQuery object, one or more elements to be returned from the selected element group. <br> <br> Tip: To specify multiple conditions, use a comma to separate them.
function(index) Optional. Specifies a function to run for each element in the set. If it returns true, the element is kept; otherwise, the element is removed. index - The index position of the element in the set. Note: this refers to the current DOM element.

More Examples

Return all even-numbered <p> elements

Multiple Conditions

Using jQuery Object

DOM

Using Function


jQuery Traversal Methods

❮ Event Delegate Misc Callbacks Fire ❯