g(..).addClass(classNames)

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).
Params:
  • classNames, required: A space delimited list of CSS classes to be applied to all elements in the Gimme Object's internal array.

Examples:
// 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
g('#main').addClass('low-resolution');

// 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)
g('p#para1').addClass('foo').addClass('bar');

// 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 8:50 PM by sstchur, version 4

Comments

No comments yet.