JavaScript onClick event - HTML table

var table = document.getElementById("tableID");
if (table != null) {
    for (var i = 0; i < table.rows.length; i++) {
        for (var j = 0; j < table.rows[i].cells.length; j++)
        table.rows[i].cells[j].onclick = function () {
            tableText(this);
        };
    }
}

function tableText(tableCell) {
    alert(tableCell.innerHTML);
}

is an example of what you could do. DEMO


Just insert onclick into each <td> of the table and if the cell's name were example, you could do something similar to this:

<td onclick="alert('You are clicking on the cell EXAMPLE')">