Skip to content
Permalink
Browse files

Changed implementation of removeClass: No more regex, tested and work…

…ing in FF1.5, IE6 and Opera9 (tests added)- see http://jquery.com/discuss/2006-September/012088/
  • Loading branch information
jzaefferer committed Sep 22, 2006
1 parent ca5b83c commit 94b0bf5f2b7a4003196a679649567a13d0f13ad0
Showing with 22 additions and 1 deletion.
  1. +22 −1 src/jquery/jquery.js
@@ -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

0 comments on commit 94b0bf5

Please sign in to comment.
You can’t perform that action at this time.