Modify ↓
Ticket #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: | |
| 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
Change History
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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

