firstChild

書式

obj.firstChild

対応

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

説明

オブジェクトの最初の子ノードを参照します。firstChildはchildNodes[0]と同じになります。

サンプルコード [実行]

<!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() {
var obj = document.getElementById("pBox");
var data = obj.childNodes[0].firstChild.nodeValue;
alert(data);
}
// --></script>
</head>
<body>
<h1>firstChild</h1>
<form>
<input type="button" id="myButton" value="Click" onClick="check()">
</form>
<div id="pBox"><span class="abc">text1</span><div id="subBox">text2</div></div>
</body>
</html>