W3C DOM tests - Accessing table elements

This table is element x.

This is the caption
th in thead td in thead td in thead
th in tfoot td in tfoot td in tfoot
th in tbody td in tbody td in tbody
td in tbody td in tbody td in tbody
td in tbody td in tbody td in tbody

This page tests a few basic HTML DOM properties.

This function is called by every test script on the page:

function showMsg(obj) {
	var insertIn = obj.getElementsByTagName('td')[0] || obj;
	insertIn.innerHTML = 'Access to ' + obj.nodeName + ' granted';
}

Test scripts

caption

var y = x.caption;
showMsg(y);

rows[]

var y = x.rows[1];
showMsg(y);

cells[]

var y = x.rows[0].cells[0];
showMsg(y);

tBodies[]

var y = x.tBodies[0];
showMsg(y);

tFoot

var y = x.tFoot;
showMsg(y);

tHead

var y = x.tHead;
showMsg(y);

innerHTML tests

var y = x.caption;
y.innerHTML = 'innerHTML works';
var y = x.rows[1];
y.innerHTML = '<td>innerHTML works</td>';
var y = x.rows[0].cells[0];
y.innerHTML = 'innerHTML works';
var y = x.tBodies[0];
y.innerHTML = '<tr><td>innerHTML works</td></tr>';
var y = x.tFoot;
y.innerHTML = '<tr><td>innerHTML works</td></tr>';
var y = x.tHead;
y.innerHTML = '<tr><td>innerHTML works</td></tr>';