Skip to main content

Bug Tracker

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 spudly comment:1

The other (nasty) alternative for adding multiple classes with one function call is:

$el.addClass(foo + ' ' + bar + ' ' + baz);

Changed October 19, 2012 02:01PM UTC by mikesherov comment:2

component: unfiledattributes
keywords: → 1.9-discuss
milestone: None1.9
status: newopen

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 dmethvin 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 mikesherov comment:4

-1

Changed October 22, 2012 05:17PM UTC by gnarf comment:5

-1, Might actually cause some issues with the jQuery UI "animate class" signature.

Changed October 26, 2012 06:42PM UTC by david71rj 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 rwaldron comment:7

Changed October 29, 2012 04:30PM UTC by dmethvin comment:8

resolution: → wontfix
status: openclosed

Voted out.

Changed November 27, 2012 05:37PM UTC by dmethvin comment:9

milestone: 1.9None