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

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -