Skip to content
Permalink
Browse files

Added test for toggleClass, fixed jQuery.className.has to accept both…

… node and className (#762)
  • Loading branch information
jzaefferer committed Jan 8, 2007
1 parent d97397d commit 76d6d445bb68009c010e0b91dbf21747bc2d35ba
Showing with 15 additions and 2 deletions.
  1. +9 −0 src/jquery/coreTest.js
  2. +6 −2 src/jquery/jquery.js
@@ -429,6 +429,15 @@ test("removeClass(String) - add three classes and remove again", function() {
ok( pass, "Remove multiple classes" );
});

test("toggleClass(String)", function() {
var e = $("#firstp");
ok( !e.is(".test"), "Assert class not present" );
e.toggleClass("test");
ok( e.is(".test"), "Assert class present" );
e.toggleClass("test");
ok( !e.is(".test"), "Assert class not present" );
});

test("removeAttr(String", function() {
ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
});
@@ -1227,20 +1227,24 @@ jQuery.extend({
},

className: {
// internal only, use addClass("class")
add: function( elem, c ){
jQuery.each( c.split(/\s+/), function(i, cur){
if ( !jQuery.className.has( elem.className, cur ) )
elem.className += ( elem.className ? " " : "" ) + cur;
});
},
// internal only, use removeClass("class")
remove: function( elem, c ){
elem.className = c ?
jQuery.grep( elem.className.split(/\s+/), function(cur){
return !jQuery.className.has( c, cur );
}).join(' ') : "";
},
has: function( classes, c ){
return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes );
// internal only, use is(".class")
has: function( t, c ) {
t = t.className || t;
return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
}
},

0 comments on commit 76d6d44

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