Javascript DOM HTML Input Date Object create

Introduction

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

Click the button to create a Date field.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {// www. j a  v a 2 s. com
  var x = document.createElement("INPUT");
  x.setAttribute("type", "date");
  x.setAttribute("value", "2020-02-09");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related