g(..).swapClass(oldClass, newClass)

Replaces the CSS class specified by oldClass with the class specified by newClass for 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).
  • oldClass, required: string indicating the CSS class to be replaced (ex: 'dog')
  • newClass, required: string specifying that CSS class that will replace oldClass (ex: 'cat')

// Swaps the class "dog" for the class "cat" for  all <div> elements on the page
g('div').swapClass('dog', 'cat');

// Swaps the class "pretty" for "ugly" and the class "small" for "big" for each <p> element that has the class "special" and which descends from #main
g('#main p.special').swapClass('pretty', 'ugly').swapClass('small', 'big');

Additional Info:
The .swapClass(..) function can only perform a 1-to-1 swap. It does not support any variation of the following:
// attempt to swap "dog" and "cat" for "canine" and "feine"  -- DON'T DO THIS; IT WON'T WORK!
g('div').swapClass('dog cat', 'canine feline');

Attempting to execute the above (or similar) code may yield unexpected results.

Last edited Jun 16, 2007 at 6:06 PM by sstchur, version 1


No comments yet.