I am creating a unordered list and a button in the for loop. I want to bind a click function for the buttons in the same for loop.
Tried with the concatenating option. It`s not working.
function displayFeeds(items){
var ul = $('#listview');
for (var i = 0; i < items.length; i++) {
var li = $('<li/>').html(items[i].DeviceNames);
li.append($('<li/>').html(items[i].DeviceQuantity));
li .append('<input type="button" value="Add" id="'+i+'">');
// Enhance new button element
li.append($('<hr>'));
ul.append(li);
$('#"+i+"').bind('click', function () {
console.log("called");
var clickedID = this.id;
console.log(clickedID);
UpdateDeviceDetails(clickedID);
});
}
}
What should I do here?