XML DOM hasAttribute()Methods
Element object
Definition and Usage
The hasAttribute() method returns TRUE if the current element node has an attribute matching the specified name, otherwise it returns FALSE.
Syntax
hasAttribute(name)
| Parameter | Description |
|---|---|
| name | Required. Specifies the attribute to look up. |
Example
The following code snippet usesloadXMLDoc()put "books.xml"Load into xmlDoc, and check whether the first <book> element has a "category" attribute:"
Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.hasAttribute("category"));
x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.hasAttribute("category"));
Output:
true
Try it Yourself »
Element objectother extensions