jquery core: Closes #1681. jQuery.fn.toggleClass can accept a boolean argument indicating add/remove.
This commit is contained in:
parent
0e3e470edc
commit
0a8f96ac3d
|
@ -1284,8 +1284,10 @@ jQuery.each({
|
||||||
jQuery.className.remove( this, classNames );
|
jQuery.className.remove( this, classNames );
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleClass: function( classNames ) {
|
toggleClass: function( classNames, state ) {
|
||||||
jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
|
if( typeof state !== "boolean" )
|
||||||
|
state = !jQuery.className.has( this, classNames );
|
||||||
|
jQuery.className[ state ? "add" : "remove" ]( this, classNames );
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function( selector ) {
|
remove: function( selector ) {
|
||||||
|
|
|
@ -1493,13 +1493,20 @@ test("removeClass(String) - simple", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("toggleClass(String)", function() {
|
test("toggleClass(String)", function() {
|
||||||
expect(3);
|
expect(6);
|
||||||
var e = jQuery("#firstp");
|
var e = jQuery("#firstp");
|
||||||
ok( !e.is(".test"), "Assert class not present" );
|
ok( !e.is(".test"), "Assert class not present" );
|
||||||
e.toggleClass("test");
|
e.toggleClass("test");
|
||||||
ok( e.is(".test"), "Assert class present" );
|
ok( e.is(".test"), "Assert class present" );
|
||||||
e.toggleClass("test");
|
e.toggleClass("test");
|
||||||
ok( !e.is(".test"), "Assert class not present" );
|
ok( !e.is(".test"), "Assert class not present" );
|
||||||
|
|
||||||
|
e.toggleClass("test", false);
|
||||||
|
ok( !e.is(".test"), "Assert class not present" );
|
||||||
|
e.toggleClass("test", true);
|
||||||
|
ok( e.is(".test"), "Assert class present" );
|
||||||
|
e.toggleClass("test", false);
|
||||||
|
ok( !e.is(".test"), "Assert class not present" );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("removeAttr(String", function() {
|
test("removeAttr(String", function() {
|
||||||
|
|
Loading…
Reference in a new issue