HTML | DOM Input Button Object

The DOM Input Type Button Object is used to represent the HTML <input> element with type=”button”. The Input Type Button element is accessed by getElementById().

Syntax:

document.getElementById("ID");

Where “id” is the ID assigned to the “input” tag.

Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1>GeeksForGeeks</h1>
    <h2> DOM Input Button Object </h2>
    
    <!-- Assigning button id -->
    <input type="button" id="GFG" onclick="myGeeks()" value="Submit">
  
    <p id="sudo"></p>
  
    <script>
        function myGeeks() {
            
            // accessing 'button' id.
            var g = document.getElementById("GFG").value;
            document.getElementById("sudo").innerHTML = 
              "Value od input type button is:" + g;
        }
    </script>
  
</body>
  
</html>

chevron_right


Output:



Before Clicking On Button :

After Clicking On Button :

Example-2: Input button Object can be created by using the document.createElement method.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
          
        #GFG {
            margin-left: 45%;
            margin-top: 30px;
        }
    </style>
</head>
  
<body>
    <h1>GeeksForGeeks</h1>
    <h2> DOM Input Button Object </h2>
    <h3 style="color:green;">
      Click the Button to Create the Buttton</h3>
    
    <button onclick="myGeeks()">Submit</button>
    <script>
        function myGeeks() {
            var g = document.createElement("INPUT");
            g.setAttribute("type", "button");
            g.setAttribute("value", "Click me");
            g.setAttribute("id", "GFG");
            document.body.appendChild(g);
        }
    </script>
  
</body>
  
</html>

chevron_right


Output:

Before Clicking On Button:

After Clicking on Button:

Supported Browsers: The browser supported by DOM Input button Object are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : shubham_singh



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.