This is my current code. What I am trying to accomplish is as follows.
If json[i].enabled is true, I need to check the corresponding checkbox. If not, leave it empty.
function createTable(json) { var element = ""; var i; for (i = 0; i < json.length; i++) { element = element + '<tr><td><input type= "checkbox"/></td><td>' + json[i].a_id + '</td><td>' + json[i].name + '</td><td>'+ json[i].enabled + '</td></tr>'; if(json[i].enabled== "TRUE"){ $('checkbox').prop('checked', true); } } //Had forgotten to add this before. element = element + '</tbody>'; $('#dataTable > tbody').remove(); $("#dataTable").append(element); } I tried it by including the following if condition but it fails.
if(json[i].enabled== "TRUE"){ $('checkbox').prop('checked', true); } So, how do I go about doing this? How do I access that particular checkbox in the loop?
Thanks!
$('checkbox')? It should be$('input[type="checkbox"]')or$('.checkbox')