Nikhil Hegde Nikhil Hegde - 1 year ago 70
HTML Question

Add a checkbox to a dynamically added table row

I have a table which I add cells to dynamically. I want to add a checkbox as one of the cell elements. Specifically to element cell_0 of row0.
I tried

cell_0.innerHTML = <input type = "checkbox />;
but that didn't work.

var row0 = document.getElementById("jobsTable").insertRow(0);
var cell_0 = row0.insertCell(0);
cell_0.innerHTML = <input type="checkbox"/> ;
var cell_1 = row0.insertCell(1);
cell_1.innerHTML = "CIT Suite";
var cell_2 = row0.insertCell(2);
cell_2.innerHTML = "Buildroot";

<table id="jobsTable" class="container" align="center" style="width:40%">

Any help is appreciated!

ray ray
Answer Source

You have to quote the html. cell_0.innerHTML = '<input type="checkbox"/>';