Why is JS triggered only by double clicking?
Task: determine the table cell by rows and cells.
Table:
<table id="my_table"> <tbody> <tr> <td>1000</td> <td>3000</td> <td>5000</td> </tr> <tr> <td onclick="myFunction(this)">300</td> <td onclick="myFunction(this)">400</td> <td onclick="myFunction(this)">500</td> </tr> <tr> <td onclick="myFunction(this)">2</td> <td onclick="myFunction(this)">3</td> <td onclick="myFunction(this)">500</td> </tr> </tbody> </table> Js
if (!document.getElementsByTagName || !document.createTextNode) return; var temp; var rows = document.getElementById('my_table').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); for (i = 0; i < rows.length; i++) { rows[i].onclick = function() { str1=this.rowIndex + 1; } }