Skip to main content

Bug Tracker

Side navigation

#6561 closed enhancement (wontfix)

Opened May 13, 2010 08:03AM UTC

Closed November 11, 2010 01:46AM UTC

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)
Change History (4)

Changed July 10, 2010 05:20PM UTC by Motty comment:1

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

Changed October 03, 2010 11:49PM UTC by Motty comment:2

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

Changed October 18, 2010 11:54PM UTC by snover comment:3

keywords: containscontains needsreview
priority: → undecided

Bikeshed/feature creep. Marking for review.

Changed November 11, 2010 01:46AM UTC by dmethvin comment:4

keywords: contains needsreviewcontains
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.