Dom Operation CREATE TABLE

Source: Internet
Author: User

To facilitate building tables, the HTML Dom adds properties and methods to the <table>, <tbody>, and <tr> elements.

The properties and methods added for the <table> element are as follows.

    • Caption: holds a pointer to the <caption> element (if any).
    • Tbodies: is a <tbody> element of the htmlcollection.
    • TFoot: Holds a pointer to the <tfoot> element (if any).
    • THead: Holds a pointer to the <thead> element (if any).
    • Rows: Is the htmlcollection of all rows in a table.
    • Createthead (): Creates a <thead> element, places it in a table, and returns a reference.
    • Createtfoot (): Creates a <tfoot> element, places it in a table, and returns a reference.
    • Createcaption (): Creates a <caption> element, places it in a table, and returns a reference.
    • Deletethead (): Delete <thead> element.
    • Deletetfoot (): Delete <tfoot> element.
    • Deletecaption (): Delete <caption> element.
    • DeleteRows (pos): Deletes the row at the specified location.
    • InsertRows (pos): Inserts a row into the rows collection at the specified location.

The properties and methods added for the <tbody> element are as follows.

    • Rows: Holds the htmlcollection of the rows in the <tbody> element.
    • DeleteRows (pos): Deletes the row at the specified location.
    • InsertRows (pos): Inserts a row into the rows collection at the specified location, returning a reference to the newly inserted.

The properties and methods added for the <tr> element are as follows.

    • Cells: Holds the htmlcollection of the cells in the <tr> element.
    • Deletecell (POS): Deletes the cell at the specified location.
    • InsertCell (POS): Inserts a cell into the cells collection at the specified location, returning a reference to the newly inserted cell.

Using these properties and methods can greatly reduce the amount of code required to create a table. For example:

1 //CREATE TABLE2 varTable = document.createelement ("table");3Table.border = 1;4Table.width = "100%";5 6 //Create Tbody7 varTbody = document.createelement ("Tbody");8 Table.appendchild (tbody);9 Ten //Create first row OneTbody.insertrow (0); ATbody.rows[0].insertcell (0); -Tbody.rows[0].cells[0].appendchild (document.createTextNode ("Cell")); -Tbody.rows[0].insertcell (1); theTbody.rows[0].cells[1].appendchild (document.createTextNode ("Cell 2,1")); -  - //Create second row -Tbody.insertrow (1); +Tbody.rows[1].insertcell (0); -Tbody.rows[1].cells[0].appendchild (document.createTextNode ("Cell")); +Tbody.rows[1].insertcell (1); ATbody.rows[1].cells[1].appendchild (document.createTextNode ("Cell 2,2")); at  - //Add a table to the body of a document -Document.body.appendChild (table);

Dom Operation CREATE TABLE

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.