0

How do I ignore case sensitivity with the :contains() Selector?

            $('.css-label:contains("' + filter + '")').each(function () {
                $(this).show();
                $(this).prev().show().prev().show().closest(".search-recipe-chkbox").css("display", "inline-block");;
            });

Context

        var input = $('.search-filter');
        input.change(function () {
            var filter = input.val().toLowerCase();
            if (filter.length == 0) { // show all if filter is empty
                $('.css-label').each(function () {
                    $(this).show();
                    $(this).prev().show().prev().show().closest(".search-recipe-chkbox").css("display", "inline-block");
                });
                return;
            }

            // hide all labels with checkboxes
            $('.css-label').each(function () {
                $(this).hide();
                $(this).prev().hide().prev().hide().closest(".search-recipe-chkbox").css("display", "none");;
            });

            // show only matched
            $('.css-label:contains("' + filter + '")').each(function () {
                $(this).show();
                $(this).prev().show().prev().show().closest(".search-recipe-chkbox").css("display", "inline-block");;
            });
        }).keyup(function () {
            $(this).change();
        });

Thank you

JAmes
  • 261
  • 1
  • 5
  • 15
  • 1
    Does this answer your question? [jQuery :contains() selector uppercase and lower case issue](https://stackoverflow.com/questions/8746882/jquery-contains-selector-uppercase-and-lower-case-issue) There are several other related links here on SO as well. – Paul T. Aug 02 '21 at 01:02
  • Yes, thank you. My fault, I actually did look at that page before but didn't understand the answer, but it works! – JAmes Aug 02 '21 at 01:41

0 Answers0