I have a index.html page with a table:
<body>
<table class="mytable">
<tr id="1">
<td>John</td>
<td>123</td>
</tr>
<tr id="2">
<td>Kate</td>
<td>456</td>
</tr>
</table>
<script src="my.js"></script>
</body>
I have included my.js in my page, I tried to get the id of the mouse clicked row in the following way in my.js:
$('.mytable tr').click(function(e){
alert('clicked.'); //even did not get alert here.
var rowId = $(this).attr('id');
alert(rowId);
});
But I did not get the row id of clicked row(no alert), where am I wrong?
---Solution---
My bad, I have one place emptied the table, which means no tr at all. that's why it does not work. Sorry for bothering.