Side navigation
#278 closed enhancement (worksforme)
Opened October 13, 2006 11:36PM UTC
Closed November 11, 2006 11:53AM UTC
Last modified March 18, 2014 03:34PM UTC
Make :contains() be optionally case insensitive
Reported by: | yehuda | Owned by: | |
---|---|---|---|
Priority: | trivial | Milestone: | |
Component: | core | Version: | |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
At the moment, :contains() is case sensitive only.
We need a way to make it optionally case insensitive.
Attachments (0)
Change History (10)
Changed October 16, 2006 12:41AM UTC by comment:1
priority: | major → trivial |
---|---|
type: | bug → enhancement |
Changed November 11, 2006 11:53AM UTC by comment:2
milestone: | 1.0 |
---|---|
resolution: | → worksforme |
status: | new → closed |
version: | 1.0 |
Changed September 03, 2008 02:13PM UTC by comment:3
If anybody's looking for a tested version of the above:
jQuery.extend(jQuery.expr[':'], { "contains-ic": "jQuery.fn.text.apply([a]).toLowerCase().indexOf(m[3].toLowerCase())>=0", });
Changed January 02, 2009 10:53PM UTC by comment:4
Thanks weaverryan, however I had an error with this code in Internet Explorer until i removed the extra comma from the second line:
CHANGE:
jQuery.extend(jQuery.expr[':'], {
"contains-ic": "jQuery.fn.text.apply([a]).toLowerCase().indexOf(m[3].toLowerCase())>=0",
});
TO:
jQuery.extend(jQuery.expr[':'], {
"contains-ic": "jQuery.fn.text.apply([a]).toLowerCase().indexOf(m[3].toLowerCase())>=0"
});
Works like a charm now!
Changed October 02, 2009 05:58PM UTC by comment:5
Replying to [comment:5 mike123]:
could someone please del. this spam?
@thewiredmous :
Firefox gives me a "X is not defined in jquery-1.3.2.js"
Changed October 02, 2009 06:10PM UTC by comment:6
Replying to [comment:6 Abro]:
$.extend($.expr[':'], { 'containsi': function(elem, i, match, array) { return (elem.textContent || elem.innerText || '').toLowerCase() .indexOf((match[3] || "").toLowerCase()) >= 0; } });
Works - thanks to Eric.
Changed July 29, 2011 03:55PM UTC by comment:7
I think contains should be case insensitive in the core.
Changed October 11, 2012 11:33PM UTC by comment:8
Agreed, insensitive should be preferred by default.
Changed October 11, 2012 11:50PM UTC by comment:9
description: | At the moment, :contains() is case sensitive only.\ \ We need a way to make it optionally case insensitive. → At the moment, :contains() is case sensitive only. \ \ We need a way to make it optionally case insensitive. |
---|
In addition to the one mentioned above, there is one (icontains
) in the docs for Sizzle:
https://github.com/jquery/sizzle/wiki/Sizzle-Documentation
As far as changing the default, forget it. That would break code. The tools are right here for meeting your needs, they don't need to be in core for you to use them.
Changed March 18, 2014 03:34PM UTC by comment:10
I appreciate that :contains() cannot be changed to case-insensitive by default because it would break existing code. However, it's unacceptable to make the user search the Internet to find the workaround mentioned in this ticket. Please add a :containsIgnoreCase() selector to base jQuery. It's silly that it doesn't have this already.
This could easily be added when required:
$.extend($.expr[':'], {
"contains-ic": "jQuery.fn.text.apply([a])toLowerCase().indexOf(m[3].toLowerCase())>=0",
});
Untested, but pretty simple.