August 7 = 356-360

Source: Internet
Author: User

14.2.2 common inclusion relationships between HTML elements

Some HTML elements can be nested with each other. For example, <div> elements can be nested with each other, while some HTML elements cannot

Nesting each other. For example, <TD> An element can only be a child element of <tr> elements, and <option> An element can only be used as <SELECT>

The child element of the element.

The HTML document also contains two object systems: Form objects and table objects.

Form objects can contain basic input objects, <SELECT> elements, and <SELECT> elements.

Contains multiple <option> elements.

A table object can contain the title (htmltablecaptionelement) Control and multiple tables.

A row (htmltablecolelement) space. Each table row can contain multiple cells (htmltablecellelement)

Control.

 

14.3 access HTML elements

To dynamically modify HTML elements, you must be able to access HTML elements. Dom provides two methods to access HTML elements.

Access HTML elements by ID.

Access HTML elements by using node relationships.

The previous method is easy to use, mainly including the getelementbyid () method provided by the document; the latter Method

The Tree nodes are accessed using the Parent-Child and sibling relationships.

 

14.3.1 access HTML elements by ID

The following method is used to access HTML elements by ID:

Document. getelementbyid (idval): returns the HTML element whose ID attribute value is idval in the document.

 

14.3.2 access HTML elements using node relationships

The attributes and methods for accessing HTML elements using node relationships are as follows:

Node parentnode: returns the parent node of the current node. Read-only attribute.

Node perviussibling: returns the previous sibling node of the current node. Read-only attribute.

Node nextsibling: returns the last sibling node of the current node. Read-only attribute.

Node [] childnodes: returns all child nodes of the current node. Read-only attribute.

Node [] getelementsbytagname (tagname): returns all child nodes of the current node with the specified tag name.

Node firstchild: returns the first subnode of the current node. Read-only attribute.

Node lastchild: returns the last child node of the current node. Read-only attribute.

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.