1

I'm looking for a solution to have a case-insensitive version of the :contains selector in jQuery. I found these two posts here on Stack Overflow:

Is there a case insensitive jQuery :contains selector?
How do I make jQuery Contains case insensitive, including jQuery 1.8+?

So basically the solution is this:

jQuery.expr[':'].Contains = function(a,i,m){ return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0; }; 

My only question is how do I use this? Where to I specify this piece of code? I'm loading jQuery in my header and afterwards I load my script.js file where I have my DOM ready function declared. I put this piece of code outside the DOM ready function but it doesn't change anything in the behaviour of the :contains selector.

1 Answer 1

3

If you put this piece of code after loading jquery, you will have one contains and one (case-insensitive) icontains selector:

$.extend($.expr[':'], { // case insensitive version of :contains icontains: function(a,i,m){ return (a.textContent||a.innerText||jQuery(a).text()||""). toLowerCase().indexOf(m[3].toLowerCase())>=0; } }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.