Difference between createElement and crateTextNode - Stack Overflow
巴扎黑2017-05-16 13:37:20
0
2
634
A question I encountered during the interview a few days ago. My answer is one to create the label and the other to create the text content. But the answer the interviewer wants is not this, so what direction should I think about?
Think about the composition and characteristics of nodes in the Dom tree structure:
Node is the root node, and both ElementNode and TextNode inherit from it.
ElementNode corresponds to the tag form, such as , it can have its own attributes: such as href, title, etc. There will also be child elements, such as another Element or Text
TextNode, as the name suggests, is a text node. It is expressed in the form of text. It does not have child nodes and has no additional attributes.
Think about the composition and characteristics of nodes in the Dom tree structure:
Node is the root node, and both ElementNode and TextNode inherit from it.
ElementNode corresponds to the tag form, such as , it can have its own attributes: such as href, title, etc. There will also be child elements, such as another Element or Text
TextNode, as the name suggests, is a text node. It is expressed in the form of text. It does not have child nodes and has no additional attributes.
Create element nodes, create text nodes