Find element with jQuery containing case-insensitive text

I recently had the need to find an element on a page based on its text content, but it needed to also be case-insensitive. Finding an element on the page based on its text is easy enough using the jQuery :contains() selector, but the text passed to this selector must match case, letter for letter.

Instead of modifying the functionality of a core jQuery selector, I created my own custom selector called :icontains(), where the “i” indicates case-insensitivity. I created a gist for this, shown below.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.