Bug Tracker

Opened 16 years ago

Closed 16 years ago

Last modified 14 years ago

#1077 closed enhancement (wontfix)

Add an on/off parameter to toggleClass()

Reported by: arrix Owned by:
Priority: major Milestone: 1.2
Component: core Version: 1.1.2
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by john)

Please consider adding an on/off parameter to jQuery.fn.toggleClass() so that we can write

$('#button-signIn').toggleClass('disabled', hasSignedIn);

instead of

$('#button-signIn')[hasSignedIn ? 'addClass' : 'removeClass']('disabled');

I think adding/removing a class according to some state is a frequent need.

Index: E:/zm/jquery/jquery/src/jquery/jquery.js
--- E:/zm/jquery/jquery/src/jquery/jquery.js	(revision 1598)
+++ E:/zm/jquery/jquery/src/jquery/jquery.js	(working copy)
@@ -2141,8 +2141,8 @@
 	removeClass: function(c){
-	toggleClass: function( c ){
-		jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
+	toggleClass: function( c, on){
+		jQuery.className[ (on == undefined ? jQuery.className.has(this,c) : !on) ? "remove" : "add" ](this, c);
 	remove: function(a){
 		if ( !a || jQuery.filter( a, [this] ).r.length )

Change History (3)

comment:1 Changed 16 years ago by brandon

I think this could be useful but at first it doesn't read very clear.

comment:2 Changed 16 years ago by john

Description: modified (diff)
Resolution: wontfix
Status: newclosed

We don't plan on implementing this feature in core - feel free to create a plugin for it.

comment:3 Changed 14 years ago by arrix

This has been added in [6000]

Note: See TracTickets for help on using tickets.