getStyle :: Element

getStyle(element, property) -> String | null Returns the given CSS property value of element. property can be specified in either of its CSS or camelized form.

This method looks up the CSS property of an element whether it was applied inline or in a stylesheet. It works around browser inconsistencies regarding float, opacity, which returns a value between 0 (fully transparent) and 1 (fully opaque), position properties (left, top, right and bottom) and when getting the dimensions (width or height) of hidden elements.

Examples

$(element).getStyle('font-size');

// equivalent:

$(element).getStyle('fontSize');

// -> '12px'

Notes

Internet Explorer returns literal values while other browsers return computed values.

Consider the following HTML snippet:

<style>

#test {

font-size: 12px;

margin-left: 1em;

}

</style>

<div id="test"></div>

$('test').getStyle('margin-left');

// -> '1em' in Internet Explorer,

// -> '12px' elsewhere.

Safari returns null for any non-inline property if the element is hidden (has display set to 'none').

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