Skip to content

Instantly share code, notes, and snippets.

@krishna19
Forked from pklauzinski/jquery.icontains.js
Created December 27, 2015 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishna19/517baa6320b3e6aaa272 to your computer and use it in GitHub Desktop.
Save krishna19/517baa6320b3e6aaa272 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