Common Dom Technologies

Source: Internet
Author: User

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];

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.