The difference between Innerhtl and createTextNode

Source: Internet
Author: User

The use of innerHTML

Tablerowobject.innerhtml

The use of createTextNode

createTextNode (data)

Returns the newly created Text node that represents the specified data string.

Difference: 1) innerHTML belongs to the HTML Dom

createTextNode belongs to the XML Dom

2) Although the effect is similar but in some cases there is a difference

1 var p=document.createelement ("P"); 2 p.classname= "message"; 3 p.innerhtml= "<b>i love js</b>"; 4 Document.body.appendChild (p);
1 var p=document.createelement ("P"); 2 p.classname= "message";    3 var textnode=document.createtextnode ("<b>i love Js</b>"); 4 P.appendchild (textnode); 5 Document.body.appendChild (p);

In the first case the rendered effect is bold text content

In the second case, the effect is <b>i love js</b> the original text.

So the difference between the two is that innerHTML will implement the HTML code contained in the text, while createTextNode simply creates the text node, so the effect returned is the plain text content.

The difference between Innerhtl and createTextNode

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.