Dave Clarke
Dave Clarke

Reputation: 2696

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

Upvotes: 5

Views: 3913

Answers (1)

Abraham
Abraham

Reputation: 20694

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!

Upvotes: 6

Related Questions