Since jQuery was not specified, I'll give a non-jQuery solution. Give an onclick
event to your cells like this:
FRUITS |
jQuery can greatly simplify this task. You can set the event handler for all cells and set the event method in one call.
js:
$(function() { //on DOM loaded method
$('#headerRow td').click(function() {
alert(this.innerHTML);
});
});
http://jsfiddle.net/xzmMj/
(similar non-jquery concept):
//execute at end of document or in a DOM ready/loaded handler
var arr = document.getElementById('headerRow')
.getElementsByTagName("td");
for(var i = 0; i < arr.length; i++) {
(function(_i){
arr[_i].onclick = function() { alert(this.innerHTML); };
})(i);
}