Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why is Attr a Node? Can it have children? Can it be a child?

Attr child children Node
0
10 Posted

Why is Attr a Node? Can it have children? Can it be a child?

0

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

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.