THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

XML DOM hasAttributeNS() Method


Element Object Reference Element Object

Example

The following code fragment loads "books_ns.xml" into xmlDoc and checks if the first <title> element has any attributes of the specified namespace and name:

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.hasAttributeNS(ns,"lang");
}

Output:

true
Try it yourself »

Definition and Usage

The hasAttributeNS() method returns TRUE if the current element node has the attribute specified by namespace and name, and FALSE otherwise.

Syntax

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

Element Object Reference Element Object