Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gr0g/e8e818235bc326639cccf55d0438e1c7 to your computer and use it in GitHub Desktop.
Save gr0g/e8e818235bc326639cccf55d0438e1c7 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