Why is Attr a Node? Can it have children? Can it be a child?
Attr is a Node because its value is actually carried by its children, which may be a mixture of Text and EntityReference nodes, and because making it a Node allows us to store it in a NamedNodeMap for easy retrieval. The getAttribute method hides this detail by returning a string representing the concatenation of all these children, and similarly setAttribute replaces the Attr’s contents with a single Text node holding the new string. To create or manipulate other children of an Attr, you have to access the Attrnode directly via the getAttributeNode and setAttributeNode methods, or by retrieving it from the element’s “attributes” NamedNodeMap. Section 1.1.1 of the Level 1 DOM Recommendation gives a list of which nodes can be parents and children of which other nodes. Attr is not a legal child of any node, so attempts to insert it as one will throw a DOMException (HIERARCHY_REQUEST_ERR).
Related Questions
- Do parental permission and child assent for research involving children have to occur at the same time or in any particular order?
- My child has been diagnosed with a cholestatic liver disease. Are my other children at risk and should they be tested?
- Why is Attr a Node? Can it have children? Can it be a child?