Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

… node and className (#762)
  • Loading branch information...
commit 76d6d445bb68009c010e0b91dbf21747bc2d35ba 1 parent d97397d
@jzaefferer jzaefferer authored
Showing with 15 additions and 2 deletions.
  1. +9 −0 src/jquery/coreTest.js
  2. +6 −2 src/jquery/jquery.js
View
9 src/jquery/coreTest.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" );
});
View
8 src/jquery/jquery.js
@@ -1227,20 +1227,24 @@ jQuery.extend({
prop: function(elem, key, value){
// Handle executable functions
return value.constructor == Function &&
+ value.call( elem ) || value;
},
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 );
+ jQuery.grep( elem.className.split(/\s+/), function(cur){
+ return !jQuery.className.has( c, cur );
+ }).join(' ') : "";
+ },
// internal only, use is(".class")
has: function( t, c ) {
t = t.className || t;
Please sign in to comment.
Something went wrong with that request. Please try again.