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 comment:1
Changed October 03, 2010 11:49PM UTC by 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 comment:3
| keywords: | contains → contains needsreview |
|---|---|
| priority: | → undecided |
Bikeshed/feature creep. Marking for review.
Changed November 11, 2010 01:46AM UTC by comment:4
| keywords: | contains needsreview → contains |
|---|---|
| resolution: | → wontfix |
| status: | new → closed |
We're not encouraging additions to the selector syntax because non-standard selectors prevent the use of native
querySelectorAll()implementations supplied by browsers.
Because of the possibility of deeply nested content, change the "$(a).text()" to "a.innerHTML".