ChildNodes Node properties in HTML

Source: Internet
Author: User

Before looking at the HTML node this thing these dumplings has been very vague, so on the internet to find a "DOM programming art" PDF document, the program tested the next

<body>    <div id= "box" onclick= "Console.log (This)" > this                

here <span class=" 1234 ">here</span> where / var div = document.getElementById (' box '). Childnodes[1].childnodes[0].nodevalue; var div = document.getElementById (' box '). ChildNodes; Console.log (div); </script>

Run in Chrome

Showing 6 nodes, let's see what these 6 nodes are

    1. Text:this
    2. H2#wrap.123:here<span class= "1234" >here</span> where
    3. Text:that

As you can see, ChildNodes is the first generation of child nodes of the current element, and the order is composed of the following combinations of nodes

    1. Text
    2. Text element text
    3. text element text element text

When. Box is only pure in text, or empty, there will also be a text node, that is, the first case

When an element exists in. box, a text node exists before and after the element, regardless of whether text is empty or not, which is the second case

Then you can

ChildNodes Node properties in HTML

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.