innerHTML attributes outerHTML attributes textContent attributes innerText attributes

  • 2020-05-12 02:16:17
  • OfStack

The innerHTML property is used to read or set the HTML code within a node.

When the outerHTML property is used to read or set HTML code, the node itself is included.

The textContent property is used to read or set the text content that the node contains.

The innerText attribute and outerText attribute get different values when they read the text content of the element node. The difference between them is that when the text attribute of a node is set, the outerText attribute causes the original element node to be replaced by the text node. Note that innerText is a non-standard property; Firefox is not supported.

1.innerText is affected by CSS, while textcontent has no such problem. For example, if the CSS rule hides a piece of text, innerText does not return that text, and textcontent does the same.

2. Text returned by innerText filters out Spaces, newlines, and enter, while textcontent does not

3. The innerText attribute is not part 1 of the DOM standard, and the Firefox browser does not even deploy this attribute, while textcontent is part 1 of the DOM standard.

That's the end of this article. I hope it will be helpful for you to get familiar with javascript.


Related articles: