Onclick run function to get Table Cell Value. What is my error? HTML, JQuery, JavaScript?

Thanks in advance for the help! I tried running the code in w3schools code editor. Outcome: Should be an alert that displays the value of the clicked cell. The following is the code: <!DOCTYPE html> <html> <head> <style> table, td { border: 1px solid... show more Thanks in advance for the help! I tried running the code in w3schools code editor.
Outcome: Should be an alert that displays the value of the clicked cell.

The following is the code:
<!DOCTYPE html>
<html>
<head>
<style>
table, td {
border: 1px solid black;
}
</style>
</head>
<body>

<p>Click on each td element to alert its position in the table row.</p>

<table>
<tr>
<td onclick="myFunction(this)">Click to show cellIndex</td>
<td onclick="myFunction(this)">Click to show cellIndex</td>
<td onclick="myFunction(this)">Click to show cellIndex</td>
</tr>
<tr>
<td onclick="myFunction(this)">Click to show cellIndex</td>
<td onclick="printCellValue(this)">Print Cell Value</td> <!--Cell in question-->
<td onclick="myFunction(this)">Click to show cellIndex</td>
</tr>
</table>

<script>
function myFunction(x) {
alert("Cell index is: " + x.cellIndex);
}
function printCellValue(x){
alert("Reached"); //Proves function is being executed
var currow = x.closest("tr");
var curcol = x.cellIndex;
var cellValue = currow.find("td.eq("+curcol+")").text(); //!!!Why is this not working!!!
alert("var cellValue = "+cellValue); //cellValue should print "Print Cell Value"
}


</script>

</body>
</html>
2 answers 2