This article mainly introduces the innerHTML attribute, outerHTML attribute, textContent attribute, and innerText attribute differences in javascript. it is a summary of my personal experience and I hope you will like it. The innerHTML attribute is used to read or set the HTML code in a node.
When the outerHTML attribute is used to read or set HTML code, the node itself is included.
The textContent attribute is used to read or set the text content contained by a node.
The innerText and outerText attributes obtain different values when reading the text content of an element node. The difference between them is that when you set the text attribute of a node, the outerText attribute will replace the original element node with the text node. Note that innerText is not a standard attribute and is not supported by Firefox.
1. innerText is affected by CSS, and textcontent does not have this problem. For example, if the CSS rule hides a text segment, innerText will not return this segment of text, while textcontent will still return.
2. the text returned by innerText will filter out spaces, line breaks, and enter keys. textcontent will not
3. the innerText attribute is not part of the DOM Standard. Firefox does not even deploy this attribute, while textcontent is part of the DOM Standard.
The above is all the content in this article. I hope it will be helpful for you to become familiar with javascript.