The difference between InnerHTML NodeValue

Source: Internet
Author: User

There are several types of nodes in the DOM, common
1. Documentation node (document, unique)
2. Element nodes (those tags div,p, etc.)
3. Attribute node (class,src this)
4. Text node (text inserted inside p,div)
Other..

Where Element.nodevalue is the value of the node, where the attribute node and text node are value, and the element node has no value.

innerHTML returns all child nodes of the node and their values as a string

As an example:
<p id="example" title="texts">  这是一段文本  <span></span></p>
VarP=Document.getElementById(' Example ');P.NodeValueNull,p is an element node, so nodevalue is nullPgetattributenode ( ' id ' ).  NodeValue //example, here Gets the attribute node to the id attribute of P, NodeValue is its attribute value p.childnodes[0]. NodeValue /* " This is a text "  P is a two child node, and the inserted text is still a node, although it is not labeled. */p . innerhtml/* " This is a text < Span></span> " here innerHTML returns the various values contained in all of the nodes contained in P, in the form of strings. */              

InnerHTML nodevalue The difference

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.