How to create the checkbox dynamically using JavaScript?

To create the checkbox dynamically using JavaScript, we use the createElement method.

For instance, we write

const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.name = "name";
checkbox.value = "value";
checkbox.id = "id";

to create an input element with createElement.

We set its type attribute to 'checkbox' to make it a checkbox by setting the type property.

Then we set its name, value and id attributes by setting the properties with the same name.