XML DOM hasAttributes() Method
Node Object
Example
The following code fragment loads "books.xml" into xmlDoc and returns whether the first <book> element has any attributes:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
��� if (xhttp.readyState == 4 && xhttp.status == 200) {
������� myFunction(xhttp);
��� }
};
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();
}
Output:
true
Try it yourself »
Definition and Usage
The hasAttributes() method returns true if the specified node has any attributes, otherwise false.
Note: If the specified node is not an Element node, the return value is always false.
Browser Support
The hasAttributes() method is supported in all major browsers.
Note: Internet Explorer 9 and earlier do not support the hasAttributes() method.
Syntax
nodeObject.hasAttributes()
Parameters
None.
Return Value
Type | Description |
---|---|
Boolean | Returns true if the specified node has any attributes, otherwise false |
Technical Details
DOM Version | Core Level 2 Node Object |
---|
Node Object