I have a web application in which I am generating some HTML content based on the response to an AJAX call. In the HTML, I am creating some links with onclick() event wired to another Javascript function in the same page. But when the page loads and the links are generated in the final rendered HTML output, clicking on the links does not call the bound Javascript function. Am I doing anything wrong here? Can someone help me how to solve this issue?
Here's the Javascript function to generate the HTML code:
function getBotsStatus() {
$.post('/bot/status', {
}).done(function(bots_status) {
all_bots_status = bots_status['bots_status'];
$('#bots_table').html('');
for (var one_job in all_bots_status) {
var text = '';
if (all_bots_status[one_job] == 'running')
text = '<tr><td>' + one_job + '</td><td>' + all_bots_status[one_job] + '</td><td><a href=\'\' onclick=\'postStartBot(\'' + one_job + '\')\'>Start</a></td></tr>';
else if (all_bots_status[one_job] == 'stopped')
text = '<tr><td>' + one_job + '</td><td>' + all_bots_status[one_job] + '</td><td><a href=\'\' onclick=\'postStopBot(\'' + one_job + '\')\'>Start</a></td></tr>';
$('#bots_table').append(text);
}
}).fail(function() {
alert('Error');
});
}