javascript - Alert not showing value of td element's id on click. -
i want id of td
element on it's click.
javascript code -
$('#example').on('click', '.alertshow', function () { var id=$(this).closest('td').attr("id"); alert(id); }
and html
<table border="1" id="example"> <tr> <td class="alertshow" id="2_0"> </td><td class="alertshow" id="2_1"> </td><td class="alertshow" id="2_2"></td> <td class="alertshow" id="2_3"></td> <tr> <tr> <td class="alertshow" id="3_0"> </td><td class="alertshow" id="3_1"> </td><td class="alertshow" id="3_2"></td> <td class="alertshow" id="3_3"></td> <tr> </table>
try this:
$('#example').on('click', '.alertshow', function () { var id=$(this).attr("id"); alert(id); }
Comments
Post a Comment