Javascript DOM HTML Input Time Object create

Introduction

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

Click the button to create a Time field.

View in separate window

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

<script>
function myFunction() {/*  w w w .j a va2  s  . c  om*/
  var x = document.createElement("INPUT");
  x.setAttribute("type", "time");
  x.setAttribute("value", "21:43:54");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related