Try this
var td = document.getElementsByTagName("td"),
titles = document.getElementsByTagName("th");
for ( var i = 0; i < td.length; i++ ) {
td[i].addEventListener("click", function() {
alert( titles[this.cellIndex].innerHTML );
}, false);
}
DEMO
UPDATE
If the click should happen on the table head only
var titles = document.getElementsByTagName("th");
for ( var i = 0, len = titles.length; i < len; i++ ) {
titles[i].addEventListener("click", function() {
alert( this.innerHTML );
}, false);
}
DEMO