Bug Tracker

Modify

Ticket #6561 (closed enhancement: wontfix)

Opened 3 years ago

Last modified 3 years ago

Enhancing the :contains() selector

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

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

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

Change History

Changed 3 years ago by Motty

comment:1 Changed 3 years ago by Motty

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

comment:2 Changed 3 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 3 years ago by snover

  • Keywords needsreview added
  • Priority set to undecided

Bikeshed/feature creep. Marking for review.

comment:4 Changed 3 years ago by dmethvin

  • Keywords needsreview removed
  • Status changed from new to closed
  • Resolution set to wontfix

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

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.