javascript - click event handler for span or td inside a table cell does not work -


i populating table when page loaded. rows created below:

        $.each(datax, function() {             $.each(this, function(kx , vx) {                      tbl_row += '<td><p id="' +'^'+$key1+':'+$keyval1 +'^'+$key2+':'+$keyval2 +'^'+$key3+':'+$keyval3 +'^'+$key4+':'+$keyval4 +'^'+$key5+':'+$keyval5+ '$$'+kx+':'+vx+ '">'+vx+'</p></td>';                      tbl_labels += "<th>"+kx+"</th>";                 })                 tbl_body += "<tr>"+tbl_row+"</tr>";                    tbl_head  = "<tr>"+tbl_labels+"</tr>";                               })              $("#table_results thead").html(tbl_head);              $("#table_results tbody").html(tbl_body);              $("#table_results").table("refresh");    

it working fine far. problem is, want handle click events table cells. tried put span , p inside cells following handlers not work

$("p").click(function (){ alert('handler click p worked'); });  $("span").click(function (){ alert('handler click span worked'); }); 

what doing wrong?

try code :

$(document).on('click', 'p', function (){     alert('handler click p worked'); });  $(document).on('click', 'span', function (){     alert('handler click span worked'); }); 

it using on method detects event on element dinamically created.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -