-1

On key press i am searching through a table to display values , but how to make this work irrespective of case insensitive

$(document).ready(function()
{
        $('#filter').on('input', function()
        {
                var val = $.trim(this.value).toLowerCase();
                var tr = $('#tagstable tbody td');
                el = tr.find('label:contains(' + val+ ')').closest('td')
                tr.not(el).fadeOut();
                el.fadeIn();
        })
});

http://jsfiddle.net/cod7ceho/216/

Pawan
  • 31,545
  • 102
  • 256
  • 434
  • Use a `filter` to return elements that match your criteria E.G: http://jsfiddle.net/cod7ceho/217/ – Moob Oct 24 '16 at 11:00

1 Answers1

0

Several ways to do this. The closest to what you already have is probably to use a filter() callback, harmonising both needle and haystack to lowercase for the search:

var el = tr.find('label').filter(function(label) {
    return $(this).text().toLowerCase().indexOf(val.toLowerCase()) !== -1;
}).closest('td');

Also beware global vars - you were missing var before your el definition.

Mitya
  • 33,629
  • 9
  • 60
  • 107