Bug Tracker

Opened 9 years ago

Closed 9 years ago

#6561 closed enhancement (wontfix)

Enhancing the :contains() selector

Reported by: Motty Owned by:
Priority: undecided Milestone: 1.4.3
Component: selector Version: 1.4.2
Keywords: contains Cc:
Blocked by: Blocking:

Description

I was hoping to have some enhancements added to the :contains() selector. We really need a content exact match selector (case sensitive and insensitive) added to the jQuery core. Here is what I have put together for consideration:

$.extend($.expr[':'],{
 containsExact: function(a,i,m){
  return $.trim($(a).text().toLowerCase()) === m[3].toLowerCase();
 },
 containsExactCase: function(a,i,m){
  return $.trim($(a).text()) === m[3];
 }
});

Attachments (1)

contains-selectors.htm (5.0 KB) - added by Motty 9 years ago.

Download all attachments as: .zip

Change History (5)

Changed 9 years ago by Motty

Attachment: contains-selectors.htm added

comment:1 Changed 9 years ago by Motty

Because of the possibility of deeply nested content, change the "$(a).text()" to "a.innerHTML".

comment:2 Changed 9 years ago by Motty

I've also thought about adding a regex verison to the mix:

$.extend($.expr[':'],{
 containsExact: function(a,i,m){
  return $.trim(a.innerHTML.toLowerCase()) === m[3].toLowerCase();
 },
 containsExactCase: function(a,i,m){
  return $.trim(a.innerHTML) === m[3];
 },
 containsRegex: function(a,i,m){
  regreg =  /^\/((?:\\\/|[^\/])+)\/([mig]{0,3})$/;
  var reg = regreg.exec(m[3]);
  return RegExp(reg[1], reg[2]).test($.trim(a.innerHTML));
 }
});

Posted a demo here: https://dl.dropbox.com/u/1510510/misc/contains-selectors.htm

comment:3 Changed 9 years ago by snover

Keywords: needsreview added
Priority: undecided

Bikeshed/feature creep. Marking for review.

comment:4 Changed 9 years ago by dmethvin

Keywords: needsreview removed
Resolution: wontfix
Status: newclosed

We're not encouraging additions to the selector syntax because non-standard selectors prevent the use of native querySelectorAll() implementations supplied by browsers.

Note: See TracTickets for help on using tickets.