setStyle :: Element

setStyle(element, styles) -> HTMLElement

 

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'

});

// -> HTMLElement

 

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

});

// -> HTMLElement

 

$(element).setStyle({

  'float''left', // notice how float is surrounded by single quotes

  opacity: 0.5

});

// -> HTMLElement

 

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.


Prototype API 1.5.0 - prototypejs.org