jQuery improve table iterator
<p>I have a table containing in every row one cell inside which is checkbox and label for that checkbox.</p>

<p>What I'm trying to do it to hide rows based on inputed text.</p>

<p>Basically this is list on names and I want to filter/hide those that don't contain entered text.</p>

<p>This is my function:</p>

<pre><code>$(function () {
$('#user_name').keyup(function () {
    if ($.trim($('input#user_name').val()) == '') {
        $('table.myList &gt;tbody &gt;tr').each(function (index, value) {
            $(this).css("display", "block");
        });
    } else {
        $('table.myList &gt;tbody &gt;tr').each(function (index, value) {
            if ($(this).find('td &gt; label').length &gt; 0) {
                if ($(this).find('td &gt; label').html().toLowerCase().indexOf($.trim($('input#user_name').val()).toLowerCase()) &gt;= 0) {
                    $(this).css("display", "block");
                } else {
                    $(this).css("display", "none");
                }
            }
        });
    }
});
});
</code></pre>

<p>This code works, if my table has 40 records its fast, but when I increment list to 500 it slows down and crashes my browser after time.</p>

<p>I'm looking for a way to improve this code to work faster.</p>

<p>Here is link to mock-up code: <a href="http://jsfiddle.net/gGxcS/" rel="nofollow">http://jsfiddle.net/gGxcS/</a></p>

<p>==UPDATE==</p>

<p>Here is my final solution based on answers of @scessor and @nnnnnn:</p>

<pre><code>$(function () {

var $tableRows = $('table.myList tr');
var lastInput = '';

$('#user_name').keyup(function () {
    var sValue = $.trim($('input#user_name').val());
    if(lastInput==sValue) return;
    if (sValue == '') {
        $tableRows.show();
    } else {
        $tableRows.each(function () {
            var oLabel = $(this).find('label');
            if (oLabel.length &gt; 0) {
                if (oLabel.text().toLowerCase().indexOf(sValue.toLowerCase()) &gt;= 0) {
                    $(this).show();
                } else {
                    $(this).hide();
                }
            }
        });
        lastInput=sValue;
    }
});

$('img.removeSelections').click(function () {
    $('table.myList input[type="checkbox"]').prop("checked", false);
})
});
</code></pre>
