src code

class method Element.getStyle

Element.getStyle(element, style) → String | null
  • style (String) – The property name to be retrieved.

Returns the given CSS property value of element. The property can be specified in either its CSS form (font-size) or its camelized form (fontSize).

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>

Then:

$('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.

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.