Innerhtm,louerthtml,innertext,outertext,nodevalue differences

Source: Internet
Author: User

1.innerHTML
The written label is parsed into an element
obox.innerhtml = "<strong>123</strong>";

Return all content including tags
Console.log (obox.innerhtml);


2.outerHTML
Set/modify content, including its own elements

Will parse the label

3.innerText
Labels written are not parsed as text insertions
Obox.innertext = "<strong>123</strong>";

Returns the contents of the text in the label (not including the label
Console.log (Obox.innertext);
Get only the text of the document;

4.outerText

Set/Modify all text content including its own elements

Labels are not parsed

5.nodeValue
You cannot manipulate a DOM element directly, set a value/return value for a non-element node

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Body>    <DivID= "box">Div<span>Span</span>    </Div></Body></HTML>

1.innerHTML

<script>    var oBox = document.getElementById ("box");     = "<p><strong>123</strong></p><p>456</p>"; </script>    

2.outerHtTML

<script>    var oBox = document.getElementById ("box");         = "<p><strong>123</strong></p><p>456</p>"; </script>

Notice the layout changes

3.innerText

<script>    var oBox = document.getElementById ("box");         = "<p><strong>123</strong></p><p>456</p>";     </script>

4.outerText

<script>    var oBox = document.getElementById ("box");     = "<p><strong>123</strong></p><p>456</p>";     </script>

5.nodeValue

operate on non-element nodes only

Invalid element node operation may report undefined error

<script>    var oBox = document.getElementById ("box");        obox.childnodes[0].nodevalue = "<p><strong>123</strong></p><p>456</p>" </script>

Innerhtm,louerthtml,innertext,outertext,nodevalue differences

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.