jQuery Mobile - Filter Anything


The filter widget can also be used to filter any element containing another element like a <div> element containing <p>.


Following example demonstrates the use of filter anything in jQuery Mobile.

<!DOCTYPE html>
      <title>Filterable Anything</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

         <input data-type = "search" id = "divOfPs-input">
      <div class = "elements" data-filter = "true" data-input = "#divOfPs-input">
         <p><strong>Paragraph one</strong> Lorem ipsum dolor sit amet, 
         consectetur adipiscing elit</p>
         <p><strong>Paragraph two</strong> sed do eiusmod tempor incididunt 
         ut labore et dolore magna aliqua</p>
         <p><strong>Paragraph three</strong> quis nostrud exercitation ullamco 
         laboris nisi ut aliquip ex ea commodo consequa </p>
         <p><strong>Paragraph four</strong>  Duis aute irure dolor in reprehenderit 
         in voluptate velit esse cillum dolore eu fugiat nulla pariatur</p>
         <p><strong>Paragraph five</strong>  Excepteur sint occaecat cupidatat non 
         proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>


Let's carry out the following steps to see how the above code works −

  • Save the above html code as filterable_anything.html file in your server root folder.

  • Open this HTML file as http://localhost/filterable_anything.html and the following output will be displayed.

Kickstart Your Career

Get certified by completing the course

Get Started