Java Script Basics (vii) HTML DOM model

Source: Internet
Author: User

One, the HTML DOM.

HTML DOM features and methods are specific to the HTML, each node in the HTML is an object, by accessing the properties and methods, to make some DOM operations more convenient, in the HTML DOM is specifically used to deal with the white oh and its elements of the properties and methods.

HTML DOM Reference manual

Here is an example table for the HTML DOM Dynamic operation table.

  1. Table Object (table)

In the HTML DOM, the Table object represents an HTML table, the TableRow object represents the rows of the HTML table, and the TableCell object represents the cells of the HTML table. HTML tables can be created in HTML using table, TableRow, and TableCell.

Property:

Rows[]: Gets all the rows in the table.

Cellls[]: Gets all the cells in the table.

Method:

Inertrow (Index): used to insert a new row at the specified position in the table.

DeleteRow (Index): Used to remove rows from a table at a specified location.

  2. TableRow Object (line)

Property:

Cells[]: Returns all cells in the current row.

RowIndex: Returns the subscript for the current row.

Method:

InsertCell (Index): Inserts a cell at the specified position in a row.

Deletecell (Index): Deletes the cell at the specified position in a row.

  3. TableCell object (cell)

Property:

CellIndex: Returns the subscript where the current cell is located

InnerHTML: Returns the HTML tag in the current cell.

Align: Sets the horizontal alignment of the cell.

ClassName: Sets the class property of the cell.

Example:

Dynamically generates rows of cells and assigns values to cells.

<HTML><Head><Scripttype= "Text/javascript">functionInsrow () {varx=document.getElementById ('myTable'). InsertRow (0)  vary=X.insertcell (0)  varZ=X.insertcell (1) y.innerhtml="NEW CELL1"z.innerhtml="NEW CELL2"  }</Script></Head><Body><TableID= "MyTable"Border= "1"><TR><TD>Row1 Cell1</TD><TD>Row1 cell2</TD></TR><TR><TD>Row2 Cell1</TD><TD>Row2 cell2</TD></TR><TR><TD>ROW3 Cell1</TD><TD>ROW3 cell2</TD></TR></Table><BR/><inputtype= "button"onclick= "Insrow ()"value= "Insert Row"></Body></HTML>

Java Script Basics (vii) HTML DOM model

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.