attributes

書式

obj.attributes[参照番号]
obj.attributes.length

対応

[IE5〜][Firefox 1〜][Safari 1〜][Opera 8〜][Netscape 6〜]

説明

オブジェクトの属性を参照/設定します。属性値によっては参照/設定できない場合があり、ブラウザによっても結果が異なります。また、名前空間を指定する識別子が含まれる場合、Safari 2で属性値が読み出せないなどの不具合があります。

サンプルコード [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=shift_jis">
<title>Sample</title>
<script type="text/javascript"><!--
function check() {
colorStr = document.body.attributes[0].value;
alert(colorStr);
typ = document.getElementById("myButton").type;
alert(typ);
}
// --></script>
</head>
<body bgcolor="#fffff0">
<h1>attributes</h1>
<form>
<input type="button" id="myButton" value="Click" onClick="check()">
</form>
</body>
</html>

サンプルコード2 [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=shift_jis">
<title>Sample</title>
<script type="text/javascript"><!--
function check() {
document.body.attributes[0].value = "#ffa0a0";
document.getElementById("myButton").value = "変更しました";
}
// --></script>
</head>
<body bgcolor="#fffff0">
<h1>attributes</h1>
<form>
<input type="button" id="myButton" value="背景色変更" onClick="check()">
</form>
</body>
</html>