Skip to Content

Blog

Tech Simplicity · Blog Tag

You case-insensitive bastard

By: Michael Diedrick on Aug 12, 2014

JQuery is an immensely useful framework in Javascript, and even better, when it misses something, like how the ':contains' selector only finds things that are the same case, it's surprisingly easy to extend.  

$.extend($.expr[":"], {
"containsNoCase": function(elem, i, match, array) {
return (elem.textContent || elem.innerText || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
}
});

Then change your :contains selector to :containsNoCase, like $("body:containsNoCase").each(....  And voila, you’ll shed a tear for both the little and big letters in no time.

read post

Tags: How-Tos Process Tech Simplicity