I am trying to make a dashboard with a start and stop feature but apparently the dynamically populated controls are not triggering the event. The code for the dynamic controls are
$(document).ready(function () {
$.ajax({
url:
"https://ul2qo9rru1.execute-api.ap-south-1.amazonaws.com/default/getChannelData",
type: "GET",
dataType: "json",
success: function (response) {
console.log(response);
var rowHtml = "";
$.each(response, function (key, value) {
rowHtml =
" <div class='col-xl-6 col-lg-12'>" +
" <div class='card card-chart'>" +
"<div class='card-header card-header-success'>" +
"<div >Status : <a>" +
value.State +
"</a></div>" +
"</div>" +
"<div class='card-body'>" +
"<h4 class='card-title'>" +
value.Name +
"</h4>" +
"<h4 class='card-title'><a class='channelid'>" +
value.ChannelId +
"</a></h4><p class='card-category'><div class='btn-group'><input class='btn mb-2 mb-md-0 btn-quarternary btn-block btn-round' type='button' value='Start' id='start1'><input class='btn mb-2 mb-md-0 btn-quarternary btn-block btn-round' type='button' value='Stop' id='stop1'></input></div></div></div> </div>";
});
$(".row").append(rowHtml);
}
});
});
The controls are populating ok but the event trigger on it is not working
$(document).ready(function(){
var channelID = $(".channelid").val();
$("#start1").click(function () {
$.ajax({
url:
"https://ul2qo9rru1.execute-api.ap-south-1.amazonaws.com/default/channelTest-startstop?state=Start&channelid=2107494",
type: "POST",
headers: { "x-api-key": "PUoZWYihWE8DZbC58sng8zOZLQcG93s5mNTedxea" },
dataType: "json",
success: function (response) {
alert(response);
}
});
});
$("#stop1").click(function () {
$.ajax({
url:
"https://ul2qo9rru1.execute-api.ap-south-1.amazonaws.com/default/channelTest-startstop?state=Stop&channelid=" +
channelID,
type: "POST",
headers: { "x-api-key": "PUoZWYihWE8DZbC58sng8zOZLQcG93s5mNTedxea" },
dataType: "json",
success: function (response) {
alert(response);
}
});
});
});
Any help would be appreciated at this point..