jQuery in Action

Changing element styling
61
3.2.2 Getting and setting styles
Although modifying the class of an element allows us to choose which predeter-
mined set of defined stylesheet styles should be applied, sometimes we want to
override the stylesheet altogether. Applying styles directly on the elements them-
selves will automatically override stylesheets, giving us more fine-grained control
over individual elements and their styles.
The
css()
method works similarly to the
attr()
method, allowing us to set an
individual
CSS
property by specifying its name and value, or a series of elements
by passing in an object. First, let's look at specifying a name and value.
Figure 3.2 The presence or absence of the
striped
class is toggled whenever the mouse cursor
enters or leaves the table.
Command syntax: css
css(name,value)
Sets the named CSS style property to the specified value for each matched element.
Parameters
name
(String) The name of the CSS property to be set.
value
(String|Number|Function) A string, number, or function containing the property
value. If a function is passed as this parameter, it will be invoked for each element
of the wrapped set with its return value serving as the value for the CSS property.
The this property for each function invocation will be set to the element being
evaluated.
Returns
The wrapped set.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.