Filtering Selections and Arrays (^) ❘ 143
FIGURE 5-3
Filtering Selections and Arrays
Two methods can be associated with fi ltering an array or a selection in jQuery’s API. One method
is called filter(), and it is used for fi ltering items from a selection exclusively. The other method is
called grep(), and it is used for fi ltering items from an array exclusively.
Filtering a Selection
The filter()method removes items from a selection using a selector or a callback function. The
following document, Example 5-4, demonstrates how filter() can use a selector to reduce items in
a selection, and how the end() method can remove a previously used fi lter:
<!DOCTYPE HTML>
<html lang='en'>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=Edge' />
<meta charset='utf-8' />
<title>Rubber Soul</title>
<script src='../jQuery.js'></script>
<script src='../jQueryUI.js'></script>
<script src='Example 5-4.js'></script>
<link href='Example 5-4.css' rel='stylesheet' />
</head>