Adds a CSS class (or classes) to each element in the Gimme Object's internal array.

Returns: Itself (the same Gimme Object is return so additional methods can be chained together seamlessly).
  • classNames, required: A space delimited list of CSS classes to be applied to all elements in the Gimme Object's internal array.

// Adds the classes "animal," "mammal," "feline," "cat," and "calico" to all <div> elements (Gimme is smart enough to avoid duplicate class names being applied)
g('div').addClass('animal mammal feline cat calico');

// Adds the class "low-resolution" to the element whose id is #main

// Add the classes "foo" and "bar" to the <p> element whose id is "para1" (this is a pointless way to do it, but it illustrates the point of chainability)

// Adds the classes "foo" and "bar" only one time each!
g('#someElem').addClass('foo bar foo bar foo foo bar bar');

Last edited Jun 12, 2007 at 7:50 PM by sstchur, version 4


No comments yet.