HTML DOM className属性

定義と使用方法

className属性は、要素のclass属性を設定または返します。

文法

object.className=classname

この例では、body要素のclass属性を取得する2つの方法を示しています:

<html>
<body id="myid" class="mystyle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body CSS クラス: " + x.className);
document.write("<br />");
document.write("別の方法: ");
document.write(document.getElementById('myid').className);
</script>
</body>
</html>

出力:

Body CSS クラス: mystyle
別の方法: mystyle