-
Book Overview & Buying
-
Table Of Contents
jQuery 1.4 Reference Guide
These methods inspect and manipulate the CSS classes assigned to elements.
Determine whether any of the matched elements are assigned the given class.
.hasClass(className)
className: The class name to search for
A Boolean indicating whether the class is assigned to an element in the set.
Elements may have more than one class assigned to them. In HTML, this is represented by separating the class names with a space:
<div id="mydiv" class="foo bar"></div>
The .hasClass() method will return true if the class is assigned to an element, and it will also return true if any other classes are assigned to it. For example, given the preceding HTML code, the following will return true:
$('#mydiv').hasClass('foo')
$('#mydiv').hasClass('bar')
Add one or more classes to each element in the set of matched elements.
.addClass(className) .addClass(function)
className: One or more class names to...
Change the font size
Change margin width
Change background colour