0

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();
            });
Karuppiah RK
  • 3,894
  • 9
  • 40
  • 80
  • possible duplicate of [JavaScript: case-insensitive search](http://stackoverflow.com/questions/177719/javascript-case-insensitive-search) – chris97ong Apr 11 '14 at 08:41

2 Answers2

1

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

Felix
  • 37,892
  • 8
  • 43
  • 55
1

Add this code to your JS code

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

Credits Here

BFigueiredo
  • 176
  • 1
  • 7