Skip to content

Commit

Permalink
Fix removeClass as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Batiste Bieler committed Nov 13, 2009
1 parent e411c6b commit 4284da3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/attributes.js
Expand Up @@ -31,13 +31,12 @@ jQuery.fn.extend({
removeClass: function( value ) {
if ( (value && typeof value === "string") || value === undefined ) {
var classNames = (value || "").split(/\s+/);

for ( var i = 0, l = this.length; i < l; i++ ) {
var elem = this[i];

if ( elem.nodeType === 1 && elem.className ) {
if ( value ) {
var className = " " + elem.className + " ";
var className = " " + elem.className + " ";
className = className.replace(/[\n\t]/g, " ");
for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
className = className.replace(" " + classNames[c] + " ", " ");
}
Expand All @@ -48,7 +47,6 @@ jQuery.fn.extend({
}
}
}

return this;
},

Expand Down
8 changes: 6 additions & 2 deletions test/unit/attributes.js
Expand Up @@ -400,7 +400,7 @@ test("removeAttr(String", function() {
});

test("addClass, removeClass, hasClass", function() {
expect(10);
expect(12);

var jq = jQuery("<p>Hi</p>"), x = jq[0];

Expand All @@ -420,11 +420,15 @@ test("addClass, removeClass, hasClass", function() {
ok( jq.hasClass("hi"), "Check has1" );
ok( jq.hasClass("bar"), "Check has2" );

var jq = jQuery("<p class='class1\nclass2\tcla.ss3'></p>");
var jq = jQuery("<p class='class1\nclass2\tcla.ss3\n'></p>");
ok( jq.hasClass("class1"), "Check hasClass with carriage return" );
ok( jq.hasClass("class2"), "Check hasClass with tab" );
ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );

jq.removeClass("class2");
ok( jq.hasClass("class2")==false, "Check the class has been properly removed" );
jq.removeClass("cla");
ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
jq.removeClass("cla.ss3");
ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" );
});

0 comments on commit 4284da3

Please sign in to comment.