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

3
  • just make a comparison using toUpperCase() and toLowerCase()....pretty straight forward Commented Jun 29, 2013 at 19:32
  • I am no jquery Guru ... Could you modify the jsfiddle code so it works? Thanks Commented Jun 29, 2013 at 19:33
  • You can find solution here stackoverflow.com/questions/5671238/… Commented Jun 29, 2013 at 19:34

3 Answers 3

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(); 
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.