THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

XML DOM getAttributeNS() Method


Element Object Reference Element Object

Example

The following code fragment loads "books_ns.xml" into xmlDoc and gets the "lang" attribute value from the first <title> element:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
��� if (xhttp.readyState == 4 && xhttp.status == 200) {
������� myFunction(xhttp);
��� }
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();

function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("title")[0];
    var ns = "http://www.w3schools.com/children/";
    document.getElementById("demo").innerHTML =
    x.getAttributeNS(ns, "lang");
}

Output:

en
Try it yourself »

Definition and Usage

The getAttributeNS() method gets an attribute value by namespace URI and name.

Syntax

elementNode.getAttributeNS(ns,name)

Parameter Description
ns Required. Specifies the namespace URI to get the attribute value from
name Required. Specifies the attribute to get the attribute value from

Element Object Reference Element Object