A HTML table is defined with <table> tag. Each table contains <tr> tags and <td> tags. <tr> tags define rows and <td> tags define cells. The contents (table cell values) between <td> and </td> tags are the data.

To get the table cell values by using javascript, the method getElementsByTagName() can be used. It can return a list of elements with input tag name.

Example Codes

There is a table with 1 row (“id” attribute is “row-id”) and 2 cells in the following example. And a javascript function getCellData() is added which will popup to two alert boxes with cells’ data. In the function, the row is got by the “id” attribute. Then it calls the function getElementByTagName(“td”) to get all contents in the tag “td” in that row. In the alert message, the cell data are got by object “innerText”.

[html]

The value of the first cell Next cell

[/html]