Reputation: 887
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 script
.
$('#search').keyup(function () {
var term = $(this).val();
if (term != '') {
$('.panel').hide();
$('.panel').filter(function () {
return $(this).text().indexOf(term) > -1
}).show();
} else {
$('.panel').show();
}
});
That works fine but only with the exactly match, if I write in the text box Hello
shows me only the Hello
words but I need that shows me to hello
, hEllO
or HELLO
, all the string no matter the lower or upper case.
Any help is really appreciated, sorry for my bad grammar.
Upvotes: 1
Views: 11559
Reputation: 3800
Try to use toLowerCase()
function to by pass case-sensitive matching, like:
$(this).text().toLowerCase().indexOf(term.toLowerCase()) > -1
Upvotes: 5
Reputation: 42460
Convert both the search string and the text you are searching in to lower case:
return $(this).text().toLowerCase().indexOf(term.toLowerCase()) > -1
Upvotes: 6