1. DOM: Document Object Model. It is an application that represents documents (such as HTML documents) and various elements (such as HTML tags and text strings) accessing and operating documents.ProgramAPI ).
2. In the Dom, the hierarchical structure of the document is represented as an inverted tree. The tree roots are down, the leaves are down, and the Tree nodes represent the content in the document. The root node of the DOM tree is the document object. The documentelement attribute reference of this object indicates the Element Object of the document root element. For HTML documents, the element objects of the document root element are <HTML> tags, and
3. Get the specified Element in the document
There are two ways to directly search for specified elements in a document: Getting elements through the element ID attribute and getting elements through the element name attribute
1) Get the element through the element ID attribute
You can use the getelementsbyid () method of the Document Object to obtain the element through the ID attribute of the element. For example, get the node whose ID attribute is useid in the documentCodeAs follows:
Document. getelementsbyid ("useid ");
2) Get the element through the name attribute of the element
You can use the getelementsbyname () method of the Document Object to obtain the element through the name attribute of the element. For example, the Code for obtaining a node whose name attribute value is username in the document is as follows:
Document. getelementsbyname ("username ");
Differences between the two:
The getelementsbyname () method returns an array. The getelementsbyid () method returns an element. If you want to use the name attribute to obtain the unique element on the page, you can obtain the element with the lower mark 0 in the returned array. For example:
Document. getelementsbyname ("username") [0];