Javascript to select td element that was clicked in a table

140

Javascript to select td element that was clicked in a table -

var tbl = document.getElementById("tableb");
    if (tbl != null) {
      for (var i = 0; i < tbl.rows.length; i++) {
        for (var j = 0; j < tbl.rows[i].cells.length; j++)
          tbl.rows[i].cells[j].onclick = function () { getval(this); };
      }
    }
    function getval(cel) {
      alert(cel.innerHTML);
      cel.setAttribute('style', 'background-color:red');
    }

Comments

Submit
0 Comments