Skip to content

Instantly share code, notes, and snippets.

@jakebresnehan
Created April 3, 2012 00:41
Show Gist options
  • Save jakebresnehan/2288330 to your computer and use it in GitHub Desktop.
Save jakebresnehan/2288330 to your computer and use it in GitHub Desktop.
Make jQuery :contains Case-Insensitive
//Code for overloading the :contains selector to be case insensitive:
//Without the overload on the :contains selector jquery would normaly only underline the second line
// New selector
jQuery.expr[':'].Contains = function(a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
// Overwrites old selecor
jQuery.expr[':'].contains = function(a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
$("div:contains('Jake')").css("text-decoration", "underline");
<div>
jake without a capital J
</div>
<div>
Jake with a capital J
</div>
<div>
JAKE in Upper case
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment