Create a Time Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Time

Introduction

You can create a <time> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
</head>//from w w w.j a  v a2s.c om
<body>

<button onclick="myFunction()">create a TIME element</button>

<script>
function myFunction() {
    var x = document.createElement("TIME");
    x.setAttribute("datetime", "2014-02-14");
    var t = document.createTextNode("Valentines day");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials