#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 )
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){ jQuery.className.remove(this,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
comment:2 Changed 16 years ago by
Description: | modified (diff) |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
We don't plan on implementing this feature in core - feel free to create a plugin for it.
Note: See
TracTickets for help on using
tickets.
I think this could be useful but at first it doesn't read very clear.