Javascript: How to perform count on visible elements only?
<p>I'm using jQuery to get a string from a search field and hide items that don't match. It loops through a list of divs and uses $(this).fadeOut(); to hide those elements. </p>

<p>This works very well, but I would like to add further searches within that search. I've added an extra search field, but of course it doesn't inherit the fade outs from the previous search and it starts again from the beginning.</p>

<p><strong>I need a way to specify to the searches to only search visible elements of the list.</strong> This needs to work in reverse order as users might enter in the the second search field, then the first.</p>

<p>Here's a JSFiddle of my code illustrating the problem </p>

<p><a href="http://jsfiddle.net/MUbPQ/" rel="nofollow">JSFiddle Here</a></p>

<p>And a code snippet of one search function</p>

<pre><code> $("#filter").keyup(function () { 
        var filter = $(this).val(),
        count = 0;
 $(".records2 div").each(function () {
 // If the list item does not contain the text phrase fade it out
        if ($(this).text().search(new RegExp(filter, "i")) &lt; 0) {
            $(this).fadeOut();

            // Show the list item if the phrase matches and increase the count by 1
        } else {
            $(this).show();
            count++;
        }
  });
  });
</code></pre>
