JQuery case insensitive contains selector - 1.8.1

I am having trouble implementing this. Of the 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? Also, where should this snippet be placed? Is the document ready?

Thanks,

Dave

+4
source share
1 answer

Do not 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 it - you simply define the function, and do not access the DOM, so it should not be inside document.ready . Just make sure you load jQuery before defining this filter and defining it before using it. Hope this helps!

+6
source

Source: https://habr.com/ru/post/1433987/


All Articles