Bug Tracker

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#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 7 years ago by spudly

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

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

comment:2 Changed 7 years ago by mikesherov

Component: unfiledattributes
Keywords: 1.9-discuss added
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.

comment:3 Changed 7 years ago by dmethvin

-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 );
Last edited 7 years ago by dmethvin (previous) (diff)

comment:4 Changed 7 years ago by mikesherov

-1

comment:5 Changed 7 years ago by gnarf

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

comment:6 Changed 6 years ago by david71rj

Maybe just accept an array?

  $el.addClass(["a b", foo, "c d"]);
  // Equivalent to: "a b foo-class c d"

comment:7 Changed 6 years ago by Rick Waldron

comment:8 Changed 6 years ago by dmethvin

Resolution: wontfix
Status: openclosed

Voted out.

comment:9 Changed 6 years ago by dmethvin

Milestone: 1.9None
Note: See TracTickets for help on using tickets.