Prototype This page is part of the Prototype JavaScript framework documentation.
Overview | (...)

Element.getStyle returns the style apllied to the element if present and null otherwise.

Availability

V1.5_rc5 (prototype V 1.4.0_rc3)

Syntax


  Element.getStyle(element, style);

Examples

with inline styling:


<p id="myparagraph" style="text-align:right">This is just some random text.</p>

<p>
  <a href="#" onclick="alert(Element.getStyle('myparagraph', 'text-align' )); return false;">
    On which side is the above paragraph aligned?
  </a>
</p>

creates:

This is just some random text.

On which side is the above paragraph aligned?

with an internal style sheet (style applied to element):


<style type="text/css">
<!--
#myotherparagraph {
    text-align:right;
} 
-->
</style>
<p id="myotherparagraph">This is just some random text.</p>

<p>
  <a href="#" onclick="alert(Element.getStyle('myotherparagraph', 'text-align' )); return false;">
    On which side is the above paragraph aligned?
  </a>
</p>

creates:

This is just some random text.

On which side is the above paragraph aligned?

with an internal style sheet (style applied to class east):


<style type="text/css">
<!--
.east {
    text-align:right;
} 
-->
</style>
<p id="thisisnotmyparagraph" class="east">This is just some random text.</p>

<p>
  <a href="#" onclick="alert(Element.getStyle('thisisnotmyparagraph', 'text-align' )); return false;">
    On which side is the above paragraph aligned?
  </a>
</p>

creates:

This is just some random text.

On which side is the above paragraph aligned?