Document.createAttribute() (Method)

Creates an Attribute object that can then set on an Element with the setAttributeNode() method.


DOM level - 1
JavaScript - 1.5
Netscape - 6.0
Property/method value type:Attribute object
JavaScript syntax:NmyDocument.createAttribute(aName)
Argument list:aNameThe name of the attribute to create

This is a new feature introduced with the DOM level 1 standard and currently available only in fully DOM compliant browsers.

The example function shows how a new attribute object can be created and set on an element. Because this is standardized at the DOM document level and is not dependent on HTML, it could work in non-web browser implementations.

This is where browser implementations of DOM functionality tend to blur the facts slightly. DOM describes a generic Document and then sub-classes that to describe an HTMLDocument. Browsers merge the two areas of functionality and simply call it a Document.

Example code:

   // A code fragment that creates an attribute and sets it on
   // an element object that is passed in:
   function attachMyAttrib(anElement, aName, aValue)
   var myNewAttr = createAttribute(aName);
   var myOldAttr = anElement.setAttributeNode(myAttr);

See also:Attr object, Attribute object