getElementById

書式

obj.getElementById(id)

属性

パラメータ 内 容
aObj id属性で指定したID名

対応

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

説明

指定したID名を持つオブジェクトを返します。

サンプルコード [実行]

<!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 setStyle() {
var divObj = document.getElementById("pBox");
divObj.style.backgroundColor = "red";
divObj.style.width = 100;
divObj.style.height = 100;
}
// --></script>
</head>
<body bgcolor="#fffff0">
<h1>getElementById</h1>
<form>
<input type="button" id="myButton" value="Click" onClick="setStyle()">
</form>
<div id="pBox"></div>
</body>
</html>