Javascript DOM HTML Input Checkbox Object create

Create an Input Checkbox Object

We can create an <input> element with type="checkbox" via document.createElement() method:

var x = document.createElement("INPUT"); x.setAttribute("type", "checkbox");

Click the button to create a Checkbox.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from  w w w  . java 2s.  c  o  m*/
  var x = document.createElement("INPUT");
  x.setAttribute("type", "checkbox");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related