class method Element.setStyle

View source on GitHub →

Element.setStyle(element, styles) → Element

Modifies element's CSS style properties. Styles are passed as a hash of property-value pairs in which the properties are specified in their camelized form.

Examples
$(element).setStyle({
  backgroundColor: '#900',
  fontSize: '12px'
});
// -> Element
Notes

The method transparently deals with browser inconsistencies for float (however, as float is a reserved keyword, you must either escape it or use cssFloat instead) and opacity (which accepts values between 0 -fully transparent- and 1 -fully opaque-). You can safely use either of the following across all browsers:

$(element).setStyle({
  cssFloat: 'left',
  opacity: 0.5
});
// -> Element
 $(element).setStyle({
  'float': 'left', // notice how float is surrounded by single quotes
  opacity: 0.5
});
// -> Element

Not all CSS shorthand properties are supported. You may only use the CSS properties described in the Document Object Model (DOM) Level 2 Style Specification.

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.