How can I dynamicaly create xhtml elements with javascript? I want to add a checkbox inside a table cell.
So I want the code to look like this:
<td>
<input type="checkbox" />
</td>
Unfortunatly the slash at the end of the input element is not added thus making it not xhtml compatible. The result of my code looks like this:
<td>
<input type="checkbox">
</td>
I tried both innerHTML as createElement but both didn't add the slash.
1)
cell.innerHTML = "<input type='checkbox' />";
2)
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
cell.appendChild(checkbox);
Is there a way to add an xhtml emement?