XML DOM hasAttributes()メソッド
❮ノードオブジェクト
例
次のコードフラグメントは、「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.hasAttributes();
}
出力:
true
定義と使用法
hasAttributes()メソッドは、指定されたノードに属性がある場合はtrueを返し、そうでない場合はfalseを返します。
注:指定されたノードが要素ノードでない場合、戻り値は常にfalseです。
ブラウザのサポート
hasAttributes()メソッドは、すべての主要なブラウザーでサポートされています。
注: Internet Explorer 9以前は、hasAttributes()メソッドをサポートしていません。
構文
nodeObject.hasAttributes()
パラメーター
なし。
戻り値
Type | Description |
---|---|
Boolean | Returns true if the specified node has any attributes, otherwise false |
技術的な詳細
DOMバージョン | コアレベル2ノードオブジェクト |
---|
❮ノードオブジェクト