Case Insensitive contains jQuery selector


/ Published in: jQuery
Save to your folder(s)

This one was not created by me, but I can't remember who originally created it. It does the same thing as the built in <code>:contains()</code> selector with one important difference, it's case insensitive. Since I usually type in all lower case (bad habit I know) I like to use it for filters. It's also a nice one to use on name filters, that way if the person using the filter doesn't use the proper case it will still pull of the name, for example if they type in "Delsoto", but the proper capitalization is "DelSoto" the default <code>:contains()</code> won't find it, but this modified <code>:Contains()</code> will. Very convient.

If you have any questions about this selector, or happen to know who made tit, post and let me know. Use it in a cool project, do the same.


Copy this code and paste it in your HTML
  1. jQuery.expr[':'].Contains = function(a,i,m){
  2. return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
  3. };

URL: http://fatfolderdesign.com/259/code/couple-of-jquery-selectors

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.