Created
June 24, 2015 20:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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