g(..).hasClass(className, [n])

Determines if an element has a specified CSS class.

Returns: true if the nth element in the Gimme Object's underlying array has the CSS class specified by className, false otherwise.
Params:
  • className, required: a string indicating the CSS class to search for.
  • n, optional (default = 0): An integer value between 0 and g(..).length - 1 inclusive, which specifies the index of the element whose .className property is to be checked.

Examples:
// Alerts a message if the #main element has the class 'pretty'
if (g('#main').hasClass('pretty')) { alert('It has the class "pretty"); }

// foo is true if the first <p> element on the page has the class 'surprise', otherwise foo is false
var foo = g('p').hasClass('surprise');

// bar is true if the 3rd <div> element that has the class 'crazy' also has the class 'very', otherwise bar is false
var bar = g('div.crazy', 2).hasClass('very');

Last edited Jun 20, 2007 at 5:40 AM by sstchur, version 2

Comments

No comments yet.