#12763 closed feature (wontfix)
Multiple arguments support in addClass
Reported by: | spudly | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | attributes | Version: | 1.8.2 |
Keywords: | 1.9-discuss | Cc: | |
Blocked by: | Blocking: |
Description
It'd sure be nice if addClass() supported multiple string arguments for times when I'm using variables for the class names. That way instead of:
$el.addClass(foo).addClass(bar).addClass(baz);
... I could write:
$el.addClass(foo, bar, baz)
Change History (9)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Component: | unfiled → attributes |
---|---|
Keywords: | 1.9-discuss added |
Milestone: | None → 1.9 |
Status: | new → open |
This probably won't happen, but we'll bring it up for discussion to be included in jQuery 1.9.
comment:3 Changed 10 years ago by
-1, Not needed.
$el.addClass( foo + ' ' + bar + ' ' + baz ); $el.addClass( [foo, bar, baz].join(" ") ); $el.addClass( arrayOfClasses.join(" ") ); $.fn.addClasses = function(){ var $self = this; $.each( arguments, function(){ $self.addClass( this ); }); return $self; }; $el.addClasses( foo, bar, baz ); $.fn.addClasses.apply( $el, arrayOfClasses );
comment:5 Changed 10 years ago by
-1, Might actually cause some issues with the jQuery UI "animate class" signature.
comment:6 Changed 10 years ago by
Maybe just accept an array?
$el.addClass(["a b", foo, "c d"]); // Equivalent to: "a b foo-class c d"
comment:9 Changed 10 years ago by
Milestone: | 1.9 → None |
---|
Note: See
TracTickets for help on using
tickets.
The other (nasty) alternative for adding multiple classes with one function call is:
$el.addClass(foo + ' ' + bar + ' ' + baz);