Skip to content

Instantly share code, notes, and snippets.

@pklauzinski
Created June 24, 2015 20:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pklauzinski/b6f836f99cfa11100488 to your computer and use it in GitHub Desktop.
Save pklauzinski/b6f836f99cfa11100488 to your computer and use it in GitHub Desktop.
Custom jQuery :icontains selector for finding element based on text in a page, case-insensitive
/**
* Example use:
* $('div:icontains("Text in page")');
* Will return jQuery object containing any/all of the following:
* <div>text in page</div>
* <div>TEXT in PAGE</div>
* <div>Text in page</div>
*/
$.expr[':'].icontains = $.expr.createPseudo(function(text) {
return function(e) {
return $(e).text().toUpperCase().indexOf(text.toUpperCase()) >= 0;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment