Prototype-element-getstyle
提供:Dev Guides
プロトタイプ-getStyle()メソッド
このメソッドは、指定された要素のCSSプロパティ値を返します。 プロパティは、CSSまたはキャメル形式のいずれかで指定できます。
したがって、_font-size_と_fontSize_の指定は同等です。
構文
element.getStyle( property );
戻り値
CSSプロパティ値、またはプロパティセットが見つからない場合はNULL。 Internet Explorerはリテラル値を返し、他のブラウザーは計算値を返します。 要素が非表示の場合、Safariは非インラインプロパティに対してnullを返します。
例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var str = $('grandfather').getStyle('margin-left');
alert("Element left margin is : " + str );
}
</script>
<style>
#grandfather {
font-size: 12px;
margin-left: 1em;
}
</style>
</head>
<body>
<p>Click the button to see the result.</p>
<div id = "grandfather">This is grand father
<div id = "father"> This is father.
<div id = "kid">This is kid</div>
</div>
</div>
<br/>
<input type = "button" value = "showResult" onclick = "showResult();"/>
</body>
</html>