Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM hasAttribute() Method

XML DOM hasAttribute() Method


Element Object Reference 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)

Parameters Description
name Required. Specifies the attribute to look for.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, and check whether the first element has a "category" attribute:

Example

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName("book")[0];

document.write(x.hasAttribute("category"));

Output:

true

Try it »


Element Object Reference Element Object