Javascript DOM HTML Input Month Object create

Introduction

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

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

Click the button to create a Month field.

View in separate window

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

<script>
function myFunction() {//  w ww. j a  v a 2  s  .  c o  m
  var x = document.createElement("INPUT");
  x.setAttribute("type", "month");
  x.setAttribute("value", "2020-01");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related