Javascript DOM HTML Time Object get

Introduction

The Time object represents an HTML <time> element.

We can access a <time> element via document.getElementById():

var x = document.getElementById("myTime");

Click the button to get the HTML content of the time element above.

The time element is supported by any of the major browsers.

The dateTime property is only supported in Firefox and Opera 12.

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Date is <time id="myTime" datetime="2020-02-14">Valentines day</time>.</p>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*w w w. j a  va  2 s .  c om*/
  var x = document.getElementById("myTime").innerHTML;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related