appendChild

書式

obj.appendChild(aObj)

属性

パラメータ 内 容
aObj 追加するオブジェクト

対応

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

説明

指定したエレメントにオブジェクトを追加します。

サンプルコード [実行]

<!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 create() {
var imgObj = document.createElement("img");
imgObj.src = "icon.jpg";
var divObj = document.getElementById("pBox");
divObj.appendChild(imgObj);
}
// --></script>
</head>
<body bgcolor="#fffff0">
<h1>appendChild</h1>
<form>
<input type="button" id="myButton" value="Click" onClick="create()">
</form>
<div id="pBox"></div>
</body>
</html>