javascript - Simple onclick in a row using jquery -


i cant figure out doing wrong in code below:

<table width='100%'>  <script>$("#101m").on("click", function() {alert($( ).text());});</script> <tr id='101m'><td  class='dayavailible'>a</td></tr>  <script>$("#101a").on("click", function() {alert($( ).text());});</script> <tr id='101a'><td  class='dayavailible'>a</td></tr>  <script>$("#101e").on("click", function() {alert($( ).text());});</script> <tr id='101e'><td  class='dayavailible'>a</td></tr> </table> 

any appreciated.

your onclick event couldn't bind rows @ time when script occurs there no element present in html, either move javascript code after html or use $(function(){ ... }); dom ready.

though suggest use modular code don't have write same code again , again.

<script> // dom ready $(function(){   $("[id*='101']").on("click", function() {      alert($( ).text());   }); }); </script> 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -