Element features are represented by Attr nodes in the DOM. You can access the Attr constructor and prototype in all browsers.
Technically, an Attr node is a node in the Attrbutes attribute of an element. The constructor function is; function Attr () {[native code]}
Although it is also called a node, the Attr type node is not part of the document tree!
Features of Attr nodes:
- NodeType: 2
- NodeName: name of the feature
- NodeValue: feature value
- PrasentNode: null
- In HTML, subnodes are not supported
- In XML, nodes of the Text and EntityReference types are supported.
The three most common methods for operating Attr nodes;
- GetAttribute ()
- SetAttribute ()
- RemoveAttribute ()
In addition, getAttributeNode (), setAttributeNode (), removeChild ()
Attr nodes have three attributes: name, value (value equivalent to nodeValue), and specified (specified is a Boolean value used to distinguish special
Is it specified in the Code or the default .)
Create the Attr node document. createAttribute (). After creation, you can only use el. setAttribute () to add the feature to the element.
Var arr = document. createAttribute ('align ';) arr. value = "center"; element. setAttributeNode (arr); // The setAttributeNode () method must be used.
You are not advised to directly access the feature node. It is best to access the attribute node through the method described above.
Note: adding attributes directly to the DOM does not become a feature of html elements.
Div. mycolor = "red"; // it does not become a feature of the div element. alert (div. getAttribute ("mycolor"); // null (except IE)