I have a table, I want to print all inner html of table cells when I click on any cell, If I do this through button it's working fine but when I do this with click on cell it's throwing an error Uncaught TypeError: Cannot read property 'innerHTML' of undefined.
function funcName(){
var allTds = document.getElementsByTagName("td");
for(var j=0; j<allTds.length;j++){
allTds[j].onclick = function(){
var chekTds = allTds[j].innerHTML;
console.log(chekTds);
}
}