Javascript--dom Access sub-node ChildNodes

Source: Internet
Author: User
Access sub-node ChildNodes

Accesses the list of all child nodes under the selected element node, the returned value can be considered an array, and he has the length property.

Grammar:

Elementnode.childnodes

Attention:

If the selected node has no child nodes, the property returns a NodeList that does not contain a node.

Let's take a look at the following code:

Operation Result:

Ie:

  Number of UL sub-nodes: 3  node Type: 1

Other browsers:

   Number of UL sub-nodes: 7   node Type: 3

Attention:

1. IE full range, Firefox, Chrome, opera, safari compatibility issues

2. The whitespace between the nodes, in Firefox, Chrome, opera, Safari browser is the text node, so IE is 3, the other browser is 7, as shown:

If you change the code to this:

<ul><li>javascript</li><li>jQuery</li><li>PHP</li></ul>

Run Result: (IE and other browser results are the same)

  Number of UL sub-nodes: 3  node Type: 1

Javascript--dom Access sub-node ChildNodes

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.