Search code examples
javascriptjquerysearchcase-insensitive

search case insensitive letters in textbox


I am trying to search the contents using jquery. Search option working fine. But, I have faced some case insensitive problem here. My full codes on jsfiddle. if i put senthil in my search it didn't show the result. Because, I have Senthil (Uppercase S) in my content. How do I find Uppercase letters in jquery?

JsFiddle

$('#search').on('input', function(){
                var text = $(this).val();
                $('.subjects a').show();    
                $('.subjects a:not(:contains(' + text + '))').hide();
                $('.subjects a span').show();
            });

Solution

  • You can use a custom expression for contains like this:

    $.expr[":"].contains = $.expr.createPseudo(function(arg) {
        return function( elem ) {
            return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
        };
    });
    

    Updated Fiddle