How do I make jQuery Contains case insensitive, including jQuery 1.8+? -


i'm trying use "contains" case insensitively. tried using solution @ following stackoverflow question, didn't work:

is there case insensitive jquery :contains selector?

for convenience, solution copied here:

jquery.extend(         jquery.expr[':'], {                  contains : "jquery(a).text().touppercase().indexof(m[3].touppercase())>=0"  }); 

here error:

error: q not function source file: /js/jquery-1.4.js?ver=1.4 line: 81 

here's i'm using it:

  $('input.preset').keyup(function() {     $(this).next().find("li").removeclass("bold");     var thematch = $(this).val();     if (thematch.length > 1){       thematch = "li:contains('" + thematch + "')";       $(this).next().find(thematch).addclass("bold");     }   }); 

my use of original case sensitive "contains" in same scenario works without errors. have ideas? i'd appreciate it.

this i'm using in current project, haven't had problems. see if have better luck format:

jquery.expr[':'].contains = function(a, i, m) {    return jquery(a).text().touppercase().indexof(m[3].touppercase()) >= 0;  }; 

in jquery 1.8 api changed, jquery 1.8+ version of be:

jquery.expr[":"].contains = jquery.expr.createpseudo(function(arg) {     return function( elem ) {         return jquery(elem).text().touppercase().indexof(arg.touppercase()) >= 0;     }; }); 

you can test out here. more detail on 1.8+ custom selectors, check out sizzle wiki here.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -