Javascript DOM HTML Input Datetime Object create

Create an Input Datetime Object

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

Example

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

Click the button to create a Datetime field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from  w  ww .  j a  v a  2s. c o m*/
  var x = document.createElement("INPUT");
  x.setAttribute("type", "datetime");
  x.setAttribute("value", "2000-02-02T08:32Z");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related