]> source.dussan.org Git - jquery.git/commitdiff
Changed implementation of removeClass: No more regex, tested and working in FF1.5...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 22 Sep 2006 21:07:04 +0000 (21:07 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 22 Sep 2006 21:07:04 +0000 (21:07 +0000)
src/jquery/jquery.js

index a0d8775177dd23b61fd5955d63c589267529f78d..b7715be353ab57e0bdda6c71ab3e8d7b5059a33a 100644 (file)
@@ -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