2

This code doesn't find UPPERCASE if searched for with lowercase uppercase vise versa same for lowercase, if searched for LOWERCASE. I was thinking of making the input and data-label to lowercase with jquery before searching, but how?

jsfiddle code here

Can someone help, thanks

MOTIVECODEX
  • 2,624
  • 14
  • 43
  • 78

3 Answers3

4

Here's an updated fiddle for you http://jsfiddle.net/jdmTZ/5/

Remove the data attribute and add it in code:

            $('.filter li').each(function() {
                $(this).attr('data-label', $(this).text().toLowerCase());
            });

Then search by lowercased input

                var input = $(this).val().toLowerCase();
000
  • 26,951
  • 10
  • 71
  • 101
2

Replace line 14 by this:

var matched = $("ul li").filter(function() { return $(this).data('label').toLowerCase().indexOf(input.toLowerCase()) >= 0; });

And change the show()/hide() logic:

$('ul li').hide();
matched.show();
matched = matched.length;

Complete fiddle

This also eliminates the problem of someone entering ] or some other special character - that would break the CSS rule in your code.

Yogu
  • 9,165
  • 5
  • 37
  • 58
1

Use toLowerCase() and $.each Updated js fiddle code

Manoj Yadav
  • 6,560
  • 1
  • 23
  • 21