JQuery filter method .filter( )

The JQuery .filter( ) method is used to select a list of objects that match the applied filter. Filters can be applied whether using selector expressions or JQuery functions:

.find (Selector Expression):

Applying the fitler $('tr').find( ' : odd') on the following HTML snippet
<tr> item 1 </tr>
<tr> item 2 </tr>
<tr> item 3 </tr>
<tr> item 4 </tr>
<tr> item 5 </tr>
<tr> item 6 </tr>

will return item 2, item 4, item 6

for more about the JQuery Seletor expressions take a look on my post JQuery Selector Expressions Demystified

.find (Function):

Applies the specified function on each item and return only those that the function evaluates to true upon.

Applying the filter expression $('tr').find(function(index) { return index == 1;}) will return the second item with index 1.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: