Explanation of innerHTML attributes, outerHTML attributes, textContent attributes, and innerText attributes _ javascript skills

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.