JQuery usage of contains and toLowerCase()


I'm trying to compare a string given in an input to a div's content using jQuery contain.

Problem is, I want to be able to check if the string is contained regardless of upper/lower case.

This is my function:

$(document).ready(function() {
    $('#dSuggest').keyup(function() {
        var dInput = this.value;
        $(".dDimension:contains('" + dInput + "')").css("display","block");

So if one of the .dDimension divs contains 'Date' and a user presses the 'd' key, I want to show that item.

is it possible?

Best Solution

You can use .filter [docs]:

var dInput = this.value.toLowerCase();

$(".dDimension").filter(function() {
    return $(this).text().toLowerCase().indexOf(dInput) > -1;