1

I want to remove case sensitivity from my search criteria. If I typed lower-case letter I want it to search through both lower-case and upper-case.

My plunker

$('#search').click(function(){ $('.contact-name').hide(); var txt = $('#search-criteria').val(); $('.contact-name:contains("' + txt + '")').show(); }); 

2 Answers 2

1

The :contains selector is case sensitive by default. If you want to make it case insensitive you would need to implement your own logic using filter() to make both the text of the element and value to search for the same case. Something like this:

$('#search').click(function(){ $('.contact-name').hide(); var txt = $('#search-criteria').val(); $('.contact-name').filter(function() { return $(this).text().toLowerCase().indexOf(txt.toLowerCase()) != -1; }).show(); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

Man why are you sooo fast? :(
0

Try something like this,

:contains is case sensitive therefore it is not working in your case

Try the FIDDLE

$('#search').click(function(){ $('.contact-name').hide(); var txt = $('#search-criteria').val().toLowerCase(); $('.contact-name').each(function(i,n){ var text = $(this).text().toLowerCase(); if(text.indexOf(txt) > -1) $(this).show(); }); }); 

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.