XML DOM hasAttribute () method
Definition and Usage
It returns TRUE if hasAttribute () method has to match the name of the specified attribute in the current element node, otherwise it returns FALSE.
grammar
hasAttribute(name)
参数 | 描述 |
---|---|
name | 必需。规定要查找的属性。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and check if the first <book> element has a "category" attributes:
Examples
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"
Element object