XML DOM hasAttributeNS()メソッド
❮要素オブジェクト
例
次のコードフラグメントは、「books_ns.xml」をxmlDocにロードし、最初の<title>要素に指定された名前空間と名前の属性があるかどうかを確認します。
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName("title")[0];
var ns = "https://www.w3schools.com/children/";
document.getElementById("demo").innerHTML =
x.hasAttributeNS(ns,"lang");
}
出力:
true
定義と使用法
hasAttributeNS()メソッドは、現在の要素ノードに名前空間と名前で指定された属性がある場合はTRUEを返し、それ以外の場合はFALSEを返します。
構文
hasAttributeNS(ns,name)
Parameter | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to find |
name | Required. Specifies the name of the attribute to find |
❮要素オブジェクト