Bug Tracker

Modify

Ticket #278 (closed enhancement: worksforme)

Opened 7 years ago

Last modified 8 months ago

Make :contains() be optionally case insensitive

Reported by: yehuda Owned by:
Priority: trivial Milestone:
Component: core Version:
Keywords: Cc:
Blocking: Blocked by:

Description (last modified by dmethvin) (diff)

At the moment, :contains() is case sensitive only.

We need a way to make it optionally case insensitive.

Change History

comment:1 Changed 7 years ago by anonymous

  • Priority changed from major to trivial
  • Type changed from bug to enhancement

comment:2 follow-up: ↓ 3 Changed 7 years ago by joern

  • Status changed from new to closed
  • Version 1.0 deleted
  • Resolution set to worksforme
  • Milestone 1.0 deleted

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.

comment:3 in reply to: ↑ 2 Changed 5 years ago by weaverryan

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",
	});

comment:4 Changed 4 years ago by thewiredmous

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!

comment:6 in reply to: ↑ 5 ; follow-up: ↓ 7 Changed 4 years ago by Abro

Replying to mike123: could someone please del. this spam?

@thewiredmous : Firefox gives me a "X is not defined in jquery-1.3.2.js"

comment:7 in reply to: ↑ 6 Changed 4 years ago by Abro

Replying to Abro:

$.extend($.expr[':'], {
  'containsi': function(elem, i, match, array)
  {
    return (elem.textContent || elem.innerText || '').toLowerCase()
    .indexOf((match[3] || "").toLowerCase()) >= 0;
  }
});

Works - thanks to  Eric.

comment:8 Changed 23 months ago by reesd

I think contains should be case insensitive in the core.

comment:9 Changed 8 months ago by anonymous

Agreed, insensitive should be preferred by default.

comment:10 Changed 8 months ago by dmethvin

  • Description modified (diff)

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.