jQuery Mobile Filters

Filterable Elements

All elements that have more than one child element, can be filtered.

How To Create a Search Field:

  • The element you want to be filterable, must include the data-filter="true" attribute.
  • Create an <input> element with a specified id and add the data-type="search" attribute. This will create a basic search field. Wrap the <input> in a form, and add the "ui-filterable" class to the <form> element - this will adjust the margin between the search field and the filterable element.
  • Then, add the data-input attribute to the filterable element. Its value must match the id of the <input> element.

Below, we have created a filterable list view:

Search for elements in a list

<form class="ui-filterable">
  <input id="myFilter" data-type="search">

<ul data-role="listview" data-filter="true" data-input="#myFilter">
  <li><a href="#">Adele</a></li>
  <li><a href="#">Billy</a></li>
  <li><a href="#">Calvin</a></li>
Try it yourself »

Tip: Use a placeholder to specify a short hint that describes the expected value of the search field:


<input id="myFilter" data-type="search" placeholder="Search for names..">
Try it yourself »

Custom Filter

The text inside each child element is the actual text that is used for filtering (like "Adele" or "B" for "Billy"). However, if you want to filter the search to a custom filter text instead, you can add the data-filtertext attribute to any child element:


<li data-filtertext="fav"><a href="#">Adele</a></li>
Try it yourself »