XML DOM hasAttributeNS() Method
Definition and Usage
If the attribute is composed of a specified namespace and name, the hasAttributeNS() method returns true; otherwise, it returns false.
Syntax:
hasAttributeNS(ns,name)
Parameters | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to be retrieved. |
name | Required. Specifies the name of the attribute to be retrieved. |
Description
This method is similar to hasAttribute() MethodSimilar, but the attribute to be checked is specified by namespace and name. Only XML documents using namespaces use this method.
Example
In all examples, we will use the XML file books_ns.xml, and the JavaScript function loadXMLDoc().
The following code snippet checks if the first <title> element in "books_ns.xml" has an attribute with the specified namespace and name:
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.codew3c.com/children/";
document.write(x.hasAttributeNS(ns,"lang")
);
The output of the above code is:
true