Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the difference between element and text node

What is the basic difference between an element node and a text node? In JS in a DOM tree as innerHTML is only valid for element nodes. I’m curious to know the difference so I can understand innerHTML completely.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In the Document Object Model (DOM), an element node is a node that represents an HTML element, such as div, p, img etc. An element node can have attributes, child nodes (including other element nodes and text nodes), and can be manipulated using JavaScript to change its attributes or add/remove child nodes.

On the other hand, a text node is a node that represents the text content of an element.

innerHTML is a property of element nodes in the DOM that allows you to set or get the HTML content of an element. It returns a string representation of the element’s children, including any text nodes. However, it is not valid for text nodes themselves.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading