mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Changed implementation of removeClass: No more regex, tested and working in FF1.5, IE6 and Opera9 (tests added)- see http://jquery.com/discuss/2006-September/012088/
This commit is contained in:
parent
ca5b83c5c9
commit
94b0bf5f2b
23
src/jquery/jquery.js
vendored
23
src/jquery/jquery.js
vendored
@ -1373,9 +1373,22 @@ jQuery.extend({
|
||||
o.className += ( o.className ? " " : "" ) + c;
|
||||
},
|
||||
remove: function(o,c){
|
||||
/*
|
||||
o.className = !c ? "" :
|
||||
o.className.replace(
|
||||
new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
|
||||
new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");*/
|
||||
if( !c ) {
|
||||
o.className = "";
|
||||
} else {
|
||||
var classes = o.className.split(" ");
|
||||
for(var i=0; i<classes.length; i++) {
|
||||
if(classes[i] == c) {
|
||||
classes.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
o.className = classes.join(' ');
|
||||
}
|
||||
},
|
||||
has: function(e,a) {
|
||||
if ( e.className != undefined )
|
||||
@ -3177,6 +3190,14 @@ jQuery.macros = {
|
||||
* }
|
||||
* ok( pass, "Remove Class" );
|
||||
*
|
||||
* @test var div = $("div").addClass("test").addClass("foo").addClass("bar");
|
||||
* div.removeClass("test").removeClass("bar").removeClass("foo");
|
||||
* var pass = true;
|
||||
* for ( var i = 0; i < div.size(); i++ ) {
|
||||
* if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
|
||||
* }
|
||||
* ok( pass, "Remove multiple classes" );
|
||||
*
|
||||
* @name removeClass
|
||||
* @type jQuery
|
||||
* @param String class A CSS class to remove from the elements
|
||||
|
Loading…
Reference in New Issue
Block a user