Table access

Test elements

This is the caption
TH in THead TD in THead TD in THead
TH in TBODY 1 TD in TBODY 1 TD in TBODY 1
TD in TBODY 1 TH in TBODY 1 TD in TBODY 1
TH in TBODY 2 TD in TBODY 2 TD in TBODY 2
TD in TFoot TH in TFoot TD in TFoot

x is the table

Test scripts

indices

Test cellIndex, rowIndex and sectionIndex by clicking on a table cell. It will show the indices.

caption

Test alert(x.caption.firstChild.nodeValue)

Test x.caption.firstChild.nodeValue = 'Is this the caption?'

rows

Test alert(x.rows.length) (should be 5)

Test alert(x.rows[1].parentNode.tagName) (should be TBODY)

cells

Test alert(x.rows[0].cells.length) (should be 3)

Test alert(document.getElementsByTagName('tr')[0].cells.length) (test for Safari; evade rows[] bugs)

Test alert(x.rows[1].cells[1].tagName) (should be TD)

Test x.rows[0].cells[1].firstChild.nodeValue = 'Change cell'

tBodies

Test alert(x.tBodies.length)

Test x.tBodies[1].innerHTML = '<tr><td colspan=3>New content</td></tr>'

Test Remove children of the second tBody and insert a new TR

tHead

Test alert(x.tHead.tagName)

Test x.tHead.innerHTML = '<tr><td colspan=3>New content</td></tr>'

Test Remove children of tHead and insert a new TR

tFoot

Test x.tFoot.innerHTML = '<tr><td colspan=3>New content</td></tr>'

Test alert(x.tFoot.tagName)

Test Remove children of tFoot and insert a new TR