mirror of
https://github.com/jquery/jquery.git
synced 2026-01-24 00:58:16 -05:00
Fix #14164: assign className in addClass/removeClass only if changed. Close gh-1331.
This commit is contained in:
committed by
Michał Gołębiowski
parent
32e803c5bc
commit
c418b94eb4
@@ -9,7 +9,7 @@ var rclass = /[\t\r\n\f]/g;
|
||||
|
||||
jQuery.fn.extend({
|
||||
addClass: function( value ) {
|
||||
var classes, elem, cur, clazz, j,
|
||||
var classes, elem, cur, clazz, j, finalValue,
|
||||
i = 0,
|
||||
len = this.length,
|
||||
proceed = typeof value === "string" && value;
|
||||
@@ -38,8 +38,12 @@ jQuery.fn.extend({
|
||||
cur += clazz + " ";
|
||||
}
|
||||
}
|
||||
elem.className = jQuery.trim( cur );
|
||||
|
||||
// only assign if different to avoid unneeded rendering.
|
||||
finalValue = jQuery.trim( cur );
|
||||
if ( elem.className !== finalValue ) {
|
||||
elem.className = finalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,7 +52,7 @@ jQuery.fn.extend({
|
||||
},
|
||||
|
||||
removeClass: function( value ) {
|
||||
var classes, elem, cur, clazz, j,
|
||||
var classes, elem, cur, clazz, j, finalValue,
|
||||
i = 0,
|
||||
len = this.length,
|
||||
proceed = arguments.length === 0 || typeof value === "string" && value;
|
||||
@@ -77,7 +81,12 @@ jQuery.fn.extend({
|
||||
cur = cur.replace( " " + clazz + " ", " " );
|
||||
}
|
||||
}
|
||||
elem.className = value ? jQuery.trim( cur ) : "";
|
||||
|
||||
// only assign if different to avoid unneeded rendering.
|
||||
finalValue = value ? jQuery.trim( cur ) : "";
|
||||
if ( elem.className !== finalValue ) {
|
||||
elem.className = finalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user