DOM Manipulation Table--html DOM

Source: Internet
Author: User

HTML CREATE TABLE:

<table berder= ' 1 ' width= ' > <thead> <tr> <th> name </th> <th> Gender </th> <th> age </th> </tr> </thead> <tbody> <tr> <th>tzr</th> <th> men </th> <th>24</th> </tr> </tr> </tbody> <tfoot> <tr> <th> end </th> </tr > </tfoot>

Instead, the DOM is created by:

window.onload=function() {    var table=document.createelement (' table ');    Table.width=300;    Table.border=1;}

Use the AppendChild () method to add a table's THEAD, tr,th. Such as:

var thead=document.createelement (' thead '); Table.appendchild (thead);

As you can see, creating tables using the DOM is tiring.

Here's a look at how to get tabular data using the DOM: get the contents of the first child node of table caption.

window.onload=function() {    var table=document.getelementbytagname (' table ') [0] ;    Alert (table.children[0].innerhtml);}

Therefore, we often use HTML DOM.

Table.caption.innerHTML;

Table.caption.innerhtml= ' Personnel table ';

Table.thead;

Table.tfoot;

Table.tbodies; Returns the Tbody collection

Table.rows; All TR Collections

Table.tbodies[0].rows; TR set of Principal tbody

table.tbodies[0].rows[1].cells[1].innerhtml; Returns the contents of the second cell in the second row of a body

Table.deletecaption ();

Table.deletethead ();

Table.tbodies[0].deleterow (0); Delete Body First row

Table.tbodies[0].rows[1].deletecell (1); Delete the second row of the body second data

Finally, we can create a table quickly and easily.

Table.createcaption (). innerhtml= ' Personnel table ';

var thead=table.createthead ();

var tr=thead.insertrow (0);

Tr.insertcell (0). innerhtml= ' Data 1 ';

Tr.insertcell (1). innerhtml= ' Data 2 ';

Tr.insertcell (2). innerhtml= ' Data 3 ';

PS:,<table>,<tbody>,<th> does not have a specific method when creating a table.

DOM Manipulation Table--html DOM

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.