Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery case insensitive contains selector - 1.8.1

I'm having trouble implementing this. From other questions I have the following snippet:

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

But I get the error: TypeError: jQuery.expr.createPseudo is not a function

Any ideas? In addition, where should this snippet be placed? Document ready?

Thanks,

Dave

like image 294
Dave Clarke Avatar asked Sep 13 '12 10:09

Dave Clarke


1 Answers

Don't use createPseudo:

jQuery.expr[":"].Contains = function(obj,index,meta) {
    return jQuery(obj).text().toUpperCase().indexOf(meta[3].toUpperCase()) >= 0;
};

From here.
It doesn't matter where you put this - you're just defining a function, not accessing the DOM - so it doesn't have to be inside document.ready. Just make sure you load jQuery before you define this filter and define it before you use it. Hope this helps!

like image 120
Abraham Avatar answered Nov 02 '22 06:11

Abraham