aboutsummaryrefslogtreecommitdiffstats
path: root/src/selector.js
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-02-16 18:23:59 +0000
committerJohn Resig <jeresig@gmail.com>2009-02-16 18:23:59 +0000
commit048fc4555f8a794239a985c63cff3f76d20d6c61 (patch)
tree25066a009b29c9c13f48f31ee2c65435d1e3c60c /src/selector.js
parent8533da939d933561aa6c516db4e544dba076a988 (diff)
downloadjquery-048fc4555f8a794239a985c63cff3f76d20d6c61.tar.gz
jquery-048fc4555f8a794239a985c63cff3f76d20d6c61.zip
Added support for class selectors and class attribute selectors on XML documents. Fixes jQuery bug #4167.
Diffstat (limited to 'src/selector.js')
-rw-r--r--src/selector.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/selector.js b/src/selector.js
index 505198b23..c97ba61ff 100644
--- a/src/selector.js
+++ b/src/selector.js
@@ -165,7 +165,8 @@ Sizzle.find = function(expr, context, isXML){
};
Sizzle.filter = function(expr, set, inplace, not){
- var old = expr, result = [], curLoop = set, match, anyFound;
+ var old = expr, result = [], curLoop = set, match, anyFound,
+ isXMLFilter = set && set[0] && isXML(set[0]);
while ( expr && set.length ) {
for ( var type in Expr.filter ) {
@@ -178,7 +179,7 @@ Sizzle.filter = function(expr, set, inplace, not){
}
if ( Expr.preFilter[ type ] ) {
- match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not );
+ match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
if ( !match ) {
anyFound = found = true;
@@ -357,9 +358,13 @@ var Expr = Sizzle.selectors = {
}
},
preFilter: {
- CLASS: function(match, curLoop, inplace, result, not){
+ CLASS: function(match, curLoop, inplace, result, not, isXML){
match = " " + match[1].replace(/\\/g, "") + " ";
+ if ( isXML ) {
+ return match;
+ }
+
for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
if ( elem ) {
if ( not ^ (elem.className && (" " + elem.className + " ").indexOf(match) >= 0) ) {
@@ -397,10 +402,10 @@ var Expr = Sizzle.selectors = {
return match;
},
- ATTR: function(match){
+ ATTR: function(match, curLoop, inplace, result, not, isXML){
var name = match[1].replace(/\\/g, "");
- if ( Expr.attrMap[name] ) {
+ if ( !isXML && Expr.attrMap[name] ) {
match[1] = Expr.attrMap[name];
}
@@ -588,7 +593,8 @@ var Expr = Sizzle.selectors = {
return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
},
CLASS: function(elem, match){
- return match.test( elem.className );
+ return (" " + (elem.className || elem.getAttribute("class")) + " ")
+ .indexOf( match ) > -1;
},
ATTR: function(elem, match){
var name = match[1],
@@ -815,8 +821,10 @@ if ( document.getElementsByClassName && document.documentElement.getElementsByCl
return;
Expr.order.splice(1, 0, "CLASS");
- Expr.find.CLASS = function(match, context) {
- return context.getElementsByClassName(match[1]);
+ Expr.find.CLASS = function(match, context, isXML) {
+ if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
+ return context.getElementsByClassName(match[1]);
+ }
};
})();