hasChildNodes

書式

オブジェクト.hasChildNodes()

説明

オブジェクトに子ノードがあるかどうかを返します。trueであれば子ノードがある、falseであればないことになります。

サンプルコード [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Sample</title>
<script type="text/javascript"><!--
window.onload = function () {
var flag = document.getElementById("subBlock").hasChildNodes();
document.getElementById("result").innerHTML = flag;
}
// --></script>
</head>
<body>
<div id="result"></div>
<div id="subBlock"><span>sample</span></div>
</body>
</html>