Open In App

HTML | DOM Input Week Object

The Input Week object in HTML DOM represents an <input> element with type = “week” attribute. The element 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 = “week” attribute.  




<!DOCTYPE html>
<html>
    <head>
        <title>
            DOM Input Week Object
        </title>
    </head>
    <body>
        <center>
            <h1 style = "color:green;">
                GeeksForGeeks
            </h1>
             
            <h2>DOM Input Week Object</h2>
                 
            <label for = "uname" style = "color:green">
                <b>Enter week</b>
            </label>
             
            <input type = "week" id = "gfg"
                placeholder = "Enter week">
             
            <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 = “week” attribute.  




<!DOCTYPE html>
<html>
    <head>
        <title>
            DOM Input Week Object
        </title>
    </head>
     
    <body>
        <center>
            <h1 style = "color:green;">
                GeeksForGeeks
            </h1>
             
            <h2>DOM Input Week Object</h2>
                 
            <label for = "uname" style = "color:green">
                <b>Enter week</b>
            </label>
             
        <p id = "GFG"></p>
 
 
 
         
            <button type = "button" onclick = "geeks()">
                Click
            </button>
             
            <!-- script to create week object -->
            <script>
                function geeks() {
                     
                    /* Create input element  */
                    var link = document.createElement("INPUT");
                     
                    /* Set the type attribute */
                    link.setAttribute("type", "week");
                     
                    /* Append node value */
                    document.getElementById("GFG").appendChild(link);
                }
            </script>
        </center>
    </body>
</html>                                         

Output: 
Before Click on the button: 
 

After Click on the button: 
 

Supported Browsers:

 


Article Tags :