Mozilla.com

  1. MDC
  2. Main Page
  3. "Sandbox/"
  4. DOM
  5. element.hasAttribute
Table of contents
  1. 1. Usage
  2. 2. Example
  3. 3. See also
Table of contents
  1. 1. Usage
  2. 2. Example
  3. 3. See also

« Gecko DOM Reference

Returns a boolean indicating whether the current element has the specified attribute.

Usage

boolVal = element.hasAttribute(attrName)
  • attrName is a string representing the name of the attribute

Example

// check that the attirbute exists 
// before you set a value 
div = document.getElementById("div1"); 
if (d.hasAttribute("align")) { 
  d.setAttribute("align", "center"); 
}

Page last modified 18:38, 8 Jan 2006 by Nickolay

Files (0)