Javascript Reference
Categories: Attr

javascript Attr Description

@March 15, 2008, 1:22 a.m.
Attr, attributeFirefox/Netscape/NN 6 IE 5 Chrome/Safari/DOM 1  

  

An abstract representation of an element's attribute name/value pair is an object known in the W3C DOM vernacular as the Attr object; in IE terminology, it is called an attribute object. They are different names for the same object. An attribute object is created in both environments via the document.createAttribute() method; the reference to the attribute object then becomes the parameter to an element's setAttributeNode() method to insert that attribute object into the element. For example:

var newAttr = document.createAttribute("author");
newAttr.value = "William Shakespeare";
document.getElementById("hamlet").setAttributeNode(newAttr);
 

Some W3C DOM element methods (most notably, the getAttributeNode() method) return attribute objects, which have properties that may be accessed like any scriptable object.

 

In the W3C DOM abstract model, the Attr object inherits all properties and methods of the Node object. Some Node object properties, however, are not inherited by the attribute object in IE/Windows until Version 6, even though they are implemented for element and text nodes in Version 5.

 
HTML Equivalent

Any name/value pair inside a start tag.

 
Object Model Reference
 
[window.]document.getElementById("elementID").attributes[i]
[window.]document.getElementById("elementID").attributes.item(i)
[window.]document.getElementById("elementID").attributes.getNamedItem[attrName]
 
Object-Specific Properties
 
expandonameownerElementspecifiedvalue
 
Object-Specific Methods

None.

 
Object-Specific Event Handler Properties

None.

Under moderation.
ascendpgjz73 - 2016-05-01

Powered by Linode.