Open In App

HTML | DOM Input Time Object

The Input Time object in HTML DOM represents an <input> element with type = “time” attribute. The time attribute can be accessed by using getElementById() method.

Syntax:  



document.getElementById("id");

where id is assigned to the <input> tag.

Property Values:  



Methods 

Example 1: This example describes the getElementById() method to access the <input> element with type = “time” attribute.  




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Input Time Object
    </title>
</head>
<body>
    <center>
        <h1 style="color:green;">
            GeeksForGeeks
        </h1>
        <h2>DOM Input Time Object</h2>
        <label for="uname" style="color:green">
            <b>Enter time</b>
        </label>
        <input type="time" id="gfg" placeholder="Enter time">
        <br><br>
        <button type="button" onclick="geeks()">
            Click
        </button>
        <p id="GFG"></p>
 
        <script>
            function geeks() {
                var link = document.getElementById("gfg").value;
                document.getElementById("GFG").innerHTML = link;
            }
        </script>
    </center>
</body>
</html>

Output: 
Before Click on the button: 

After Click on the button: 

Example 2: This example describes the document.createElement() method to create <input> element with type = “time” attribute.  




<!DOCTYPE html>
<html>
<head>
    <title>
        DOM Input Time Object
    </title>
</head>
<body>
    <center>
        <h1 style="color:green">
            GeeksForGeeks
        </h1>
        <h2>DOM Input time Object </h2>
        <label for="uname" style="color:green">
            <b>Enter time</b>
        </label>
        <p id="GFG"></p>
 
        <button type="button" onclick="myGeeks()">
            Click
        </button>
        <script>
            function myGeeks() {
                var link = document.createElement("INPUT");
                link.setAttribute("type", "time");
                link.setAttribute("value", "08:08:19");
                document.getElementById("GFG").appendChild(link);
            }
        </script>
    </center>
</body>
</html>

Output: 
Before Click on the button: 

After Click on the button: 

Supported Browsers:


Article Tags :