Child nodes in JavaScript find, childnodes and children

Source: Internet
Author: User

First, find the element:

1.getElementById (): Receives a parameter: the ID of the element to be taken. Returns the element if the corresponding element is found, or null if no element with the corresponding ID exists. Match strictly, including case.

IE7 and lower versions also added an interesting "quirk" to this method: the form element with the name attribute matching the given ID (<input>, <textarea>, <button>, and <select> ) will also be returned by this method. If the name attribute of a FORM element equals the specified ID, and the element is in front of the element with the given ID in the document, IE returns that form element.

2.getElementsByTagName (). This method takes a parameter, which is to get the label name of the element, and returns a NodeList that contains 0 or more elements.

3.getElementsByName (). As the name implies, this method returns all elements with the given name attribute. The most common use of the Getelementsbyname () method is to obtain a radio button.

Second, find the element direct point:

1. Element. ChildNodes: read-only attribute child node list collection, which contains text and element type nodes.

2. Element. Children: read-only attribute child node list collection, containing only element type nodes.

3. Element. NodeType: Read-only property the node type of the current element
ELEMENT node: 1
Attribute node: 2
Text nodes: 3

  

<! DOCTYPE html>

  

  

<! DOCTYPE html>

Summary: IE8 in children and ChildNodes properties, including annotation nodes and ELEMENT nodes. But after the IE9 version children returns only the ELEMENT nodes, ChildNodes returns comments, blanks, and ELEMENT nodes.

  

Child nodes in JavaScript find, childnodes and children

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.