Javascript-Node Properties detailed

Source: Internet
Author: User

javascript-Node Attribute resolution

Each component in the dom,html document is a node. HTML is the root node.

The DOM (Document Object Model) is defined as:

The entire document is a document node
Each HTML tag is an element node
Text that is contained in an HTML element is a text node
Each HTML attribute is an attribute node
Comments belong to note nodes

First, how to get the node reference

1. How the node reference was previously obtained:
getElementById ()
Getelementbytagname ()
Getelementbyname ()

Disadvantage:
1. Wasting memory
2. Not strong logic


2. Obtain a reference to a node through the node relationship property:
Object. parentnode get a reference to the parent node
Object. ChildNodes gets the collection of child nodes
Object. FirstChild get the first child node
Object. LastChild get the last child node
Object. nextSibling get a reference to the next sibling node
Object. PreviousSibling get a reference to the previous sibling node

Disadvantage: Poor compatibility.

Second, node information (attributes)

Node type node name node value
NodeType (value) NodeName NodeValue

Element node 1 label name null

Attribute Node 2 Property Name property value

Text Node 3 #text text

Note Node 8 #comment The text of the note,

Document node 9 #document null

Javascript-Node Properties detailed

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.