M. Gar M. Gar - 1 year ago 64
Javascript Question

Search text no matter if is in lower or upper case

I have a function that I use to search content in my web using one text box

<input class="form-control" id="search" type="text" placeholder="Search" />
the showing content are in different panels, so this is my

$('#search').keyup(function () {
var term = $(this).val();
if (term != '') {
$('.panel').filter(function () {
return $(this).text().indexOf(term) > -1
} else {

That works fine but only with the exactly match, if I write in the text box
shows me only the
words but I need that shows me to
, all the string no matter the lower or upper case.

Any help is really appreciated, sorry for my bad grammar.

Answer Source

Convert both the search string and the text you are searching in to lower case:

return $(this).text().toLowerCase().indexOf(term.toLowerCase()) > -1

More info on MDN

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download