Appendix H
CSS
Method | Description | Return Value |
CSS | ||
css( property) |
Returns the specified CSS property value from the first selected element—for example:$('div').css('background-color') |
String |
css( properties) |
Sets the specified CSS properties. The properties argument is defined as an object literal of key, value pairs—for example:$('div').css({ backgroundColor : 'red', marginLeft : '10px' }); |
jQuery |
css( property, value) |
Sets the specified CSS property value—for example:$('div').css('background', 'red'); |
jQuery |
CLASS NAMES | ||
addClass() |
Adds the specified class name(s) to the selected element(s). Multiple class names are separated by spaces. | jQuery |
hasClass( className) |
Determines whether the selected element(s) have the specified class name. This method does not support multiple class names at the time of this writing. | Boolean |
removeClass( className) |
Removes the class name(s) from the selected element(s). Multiple class names are separated by spaces. | jQuery |
toggleClass( className) |
Adds or removes one or more class names from the selected elements. Multiple class names are separated by spaces. | jQuery |
POSITIONING | ||
offset() |
Returns the offset position of the first selected element relative to the viewport—for example:var offset = $('div').offset(); alert('Left: ' + offset.left); alert('Top: ' + offset.top); |
Object |
position() |
Gets the coordinates of the element relative to the offset parent—for example:var position = $('div').position(); alert('Left: ' + position.left); ... |
Get Web Development with jQuery now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.