Почему JS срабатывает только при двойном нажатии?
Задача: определить ячейку таблицы по rows и cells.
Таблица:
<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;
}
}