0

I used following code to insert some buttons inside different table rows:

$('#' + data.Symbol).append('<td><button id="deletestock' + data.Symbol + '" type="submit" class="btn btn-default"><span class="glyphicon glyphicon-trash"></span></button></td>');

And then when I tried to set an onclick listener to these button, they didn't work, my code of listener is as follow:

$(function(){
$('button').on('click', function(event){ 
    alert(this.id);
});
});

Could you please help me with this? Thank you so much!

Paul
  • 129
  • 2
  • 9
  • 2
    Read about [`Event delegation`](https://learn.jquery.com/events/event-delegation/) – Rayon Apr 04 '16 at 04:27
  • 2
    `$('table').on('click', 'button[id^="deletestock"]', function(event){ alert(this.id); });` – Rayon Apr 04 '16 at 04:27

0 Answers0