title: jQuery - Trying to filter divs on keyup
body: <p><strong>Revised Code</strong></p>
  
  <pre><code>jQuery(function($) {
  $("#filter").keyup(function () {
      var filter = $(this).val(), count = 0;
      $(".filtered h2").each(function () {
      if ($(this).text().search(new RegExp(filter, "i")) != -1) {
              $(this).parent().addClass("hidden");
      } else {
              $(this).parent().removeClass("hidden");
              count++;
      }
      $("#filter-count").text(count);
      });
  });
  
  });
  </code></pre>
  
  <p>I have a number of divs that are listed and I want to be able to add an input field that will allow a user to start typing and the divs are filtered according to each divs h2 tag.  I'm trying the code below, but it's not filtering.  It's not throwing up any errors either, so I'm not sure what to do at this point...  </p>
  
  <p>Here's the html markup:</p>
  
  <pre><code>    &lt;input id="filter" name="filter" size="40"/&gt;
  
      &lt;div class="filtered"&gt;
  
          &lt;div class="archive-row clearfix"&gt;
               &lt;label&gt;Creator: &lt;/label&gt;&lt;h2 class="hidden"&gt;Alchemy&lt;/h2&gt;
                  &lt;label&gt;Title: &lt;/label&gt; &lt;p&gt;Cras velit eros, eleifend ut viverra &lt;/p&gt;
                  &lt;label&gt;Summary: &lt;/label&gt;&lt;p&gt;Etiam lobortis, risus a dignissim tempor, neque sapien lobortis mi, quis semper sapien nisi dictum nisi. Integer neque neque&lt;/p&gt;
          &lt;/div&gt;
  
       &lt;div class="archive-row clearfix"&gt;
           &lt;label&gt;Creator: &lt;/label&gt;&lt;h2 class="hidden"&gt;Mathematics&lt;/h2&gt;
              &lt;label&gt;Title: &lt;/label&gt; &lt;p&gt;Cras velit eros, eleifend ut viverra &lt;/p&gt;
              &lt;label&gt;Summary: &lt;/label&gt;&lt;p&gt;Etiam lobortis, risus a dignissim tempor, neque sapien lobortis mi, quis semper sapien nisi dictum nisi. Integer neque neque&lt;/p&gt;
          &lt;/div&gt;
  
       &lt;div class="archive-row clearfix"&gt;
           &lt;label&gt;Creator: &lt;/label&gt;&lt;h2 class="hidden"&gt;English&lt;/h2&gt;
              &lt;label&gt;Title: &lt;/label&gt; &lt;p&gt;Cras velit eros, eleifend ut viverra &lt;/p&gt;
              &lt;label&gt;Summary: &lt;/label&gt;&lt;p&gt;Etiam lobortis, risus a dignissim tempor, neque sapien lobortis mi, quis semper sapien nisi dictum nisi. Integer neque neque&lt;/p&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>Here's the jquery... </p>
  
  <pre><code>$(document).ready(function() {
  
  $("#filter").keyup(function () {
      var filter = $(this).val(), count = 0;
      $(".filtered h2").each(function () {
   if ($(this).text().search(new RegExp(filter, "i")) &lt; 0) {
              $(this).addClass("hidden");
   } else {
              $(this).removeClass("hidden");
              count++;
   }
      });
      $("#filter-count").text(count);
  });
  
  });
  </code></pre>