Dev Dev - 23 days ago 6
jQuery Question

Add class to div

How to add class to div while creating dynamic input.

div.class = "form-group";


Not working for me. which is commented in bellow code.

<script type="text/javascript">
function dynInput(cbox) {
if (cbox.checked) {
var input = document.createElement("input");
input.type = "text";
var div = document.createElement("div");
div.id = cbox.value;
//div.class = "form-group";
div.innerHTML = "<label>Cost Per Test For " + cbox.value + "</label>";
div.appendChild(input);
document.getElementById("insertinputs").appendChild(div);
} else {
document.getElementById(cbox.value).remove();
}
}
</script>

Answer

Need to change to this:

  div.className = "form-group";