aboutsummaryrefslogtreecommitdiffstats
path: root/src/attributes.js
diff options
context:
space:
mode:
authortimmywil <tim.willison@thisismedium.com>2011-06-19 18:58:47 -0400
committertimmywil <tim.willison@thisismedium.com>2011-06-19 18:58:47 -0400
commit96501d38a935187461d45c40f17f8327b2e7cd91 (patch)
tree81afb274f687b6b83773d865f0486b81c4b52ef0 /src/attributes.js
parent124817e6684086ccf74e509309b73d4b4dd89932 (diff)
downloadjquery-96501d38a935187461d45c40f17f8327b2e7cd91.tar.gz
jquery-96501d38a935187461d45c40f17f8327b2e7cd91.zip
Allow similarly named classes (regression from 9499) and switch class retrieval to property when passing class to value functions. Fixes #9617.
Diffstat (limited to 'src/attributes.js')
-rw-r--r--src/attributes.js20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/attributes.js b/src/attributes.js
index ce7b35021..1e0e79f4b 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -37,12 +37,12 @@ jQuery.fn.extend({
},
addClass: function( value ) {
- var classNames, i, l, elem, setClass, c, cl;
+ var classNames, i, l, elem,
+ setClass, c, cl;
if ( jQuery.isFunction( value ) ) {
return this.each(function( j ) {
- var self = jQuery( this );
- self.addClass( value.call(this, j, self.attr("class") || "") );
+ jQuery( this ).addClass( value.call(this, j, this.className) );
});
}
@@ -57,11 +57,11 @@ jQuery.fn.extend({
elem.className = value;
} else {
- setClass = elem.className;
+ setClass = " " + elem.className + " ";
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
- if ( !~setClass.indexOf(classNames[ c ]) ) {
- setClass += " " + classNames[ c ];
+ if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
+ setClass += classNames[ c ] + " ";
}
}
elem.className = jQuery.trim( setClass );
@@ -78,8 +78,7 @@ jQuery.fn.extend({
if ( jQuery.isFunction( value ) ) {
return this.each(function( j ) {
- var self = jQuery( this );
- self.removeClass( value.call(this, j, self.attr("class")) );
+ jQuery( this ).removeClass( value.call(this, j, this.className) );
});
}
@@ -112,9 +111,8 @@ jQuery.fn.extend({
isBool = typeof stateVal === "boolean";
if ( jQuery.isFunction( value ) ) {
- return this.each(function(i) {
- var self = jQuery(this);
- self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );
+ return this.each(function( i ) {
+ jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
});
}