XML DOM hasChildNodes()メソッド
❮ノードオブジェクト
例
次のコードフラグメントは、「books.xml」をxmlDocにロードし、最初の<book>要素に子ノードがあるかどうかを返します。
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName('book')[0];
document.getElementById("demo").innerHTML =
x.hasChildNodes();
}
上記のコードの出力は次のようになります。
true
定義と使用法
hasChildNodes()メソッドは、指定されたノードに子ノードがある場合はtrueを返し、そうでない場合はfalseを返します。
ブラウザのサポート
hasChildNodes()メソッドは、すべての主要なブラウザーでサポートされています。
構文
nodeObject.hasChildNodes()
パラメーター
なし。
戻り値
Type | Description |
---|---|
Boolean | Returns true if the specified node has any child nodes, otherwise false |
技術的な詳細
DOMバージョン | コアレベル1ノードオブジェクト |
---|
❮ノードオブジェクト