Side navigation
#12763 closed feature (wontfix)
Opened October 18, 2012 01:57PM UTC
Closed October 29, 2012 04:30PM UTC
Last modified November 27, 2012 05:37PM UTC
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)
Attachments (0)
Change History (9)
Changed October 18, 2012 02:00PM UTC by comment:1
Changed October 19, 2012 02:01PM UTC by comment:2
component: | unfiled → attributes |
---|---|
keywords: | → 1.9-discuss |
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.
Changed October 19, 2012 04:31PM UTC by comment:3
_comment0: | -1, Not needed. → 1350664955351616 |
---|
-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 );
Changed October 19, 2012 04:44PM UTC by comment:4
-1
Changed October 22, 2012 05:17PM UTC by comment:5
-1, Might actually cause some issues with the jQuery UI "animate class" signature.
Changed October 26, 2012 06:42PM UTC by comment:6
Maybe just accept an array?
$el.addClass(["a b", foo, "c d"]); // Equivalent to: "a b foo-class c d"
Changed October 26, 2012 06:52PM UTC by comment:7
-1
@david71rj see: http://bugs.jquery.com/ticket/12380
Changed October 29, 2012 04:30PM UTC by comment:8
resolution: | → wontfix |
---|---|
status: | open → closed |
Voted out.
Changed November 27, 2012 05:37PM UTC by comment:9
milestone: | 1.9 → None |
---|
The other (nasty) alternative for adding multiple classes with one function call is: