Javascript DOM HTML Time Object create

Introduction

We can create a <time> element via the document.createElement() method:

var x = document.createElement("TIME");

Click the button to create a TIME element that set the date.

View in separate window

<!DOCTYPE html>
<html>
<head>
</head>/*from ww w .  jav  a 2  s  .c o m*/
<body>
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {
  var x = document.createElement("TIME");
  x.setAttribute("datetime", "2020-02-14");
  var t = document.createTextNode("Valentines day");
  x.appendChild(t);
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related