Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Input Email Object

  • Last Updated : 29 Jun, 2021

The Input Email Object in HTML DOM is used to represent the HTML input element with type=”email” attribute. The input element with type=”email” attribute can be accessed by using getElementById() method.

Syntax: 

  • It is used to access input email object. 
document.getElementById("id");
  • It is used to create input element. 
document.createElement("input");

Input Email Object Properties:  

PropertyDescription
typeThis property is used to return the type of form element to the email field.
valueThis property is used to set or return the value of the value attribute of an email field.
autocompleteThis property is used to set or return the value of the autocomplete attribute of an email field.
autofocusThis property is used to set or return whether an email field should automatically get focus when the page loads.
defaultValueThis property is used to set or return the default value of an email field.
disabledThis property is used to set or return whether an email field is disabled or not.
formThis property is used to return reference to the form that contains the email field.
listThis property is used to return a reference to the datalist that contains the email field.
maxLengthThis property is used to set or return the value of the maxlength attribute of an email field.
multipleThis property is used to set or return whether a user is allowed to enter more than one email address in the email field.
nameThis property is used to set or return the value of the name attribute of an email field.
patternThis property is used to set or return the value of the pattern attribute of an email field.
placeholderThis property is used to set or return the value of the placeholder attribute of an email field.
readOnlyThis property is used to set or return whether the email field is read-only or not.
requiredThis property is used to set or return whether the email field must be filled out before submitting a form.
sizeThis property is used to set or return the value of the size attribute of the email field.

Example 1: This example uses getElementById() method to access <input> element with type=”email” attribute.  

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        HTML DOM Input Email Object
    </title>
</head>   
 
<body>
 
    <h1> GeeksforGeeks</h1>
 
    <h2>DOM Input Email Object</h2>
 
    E-mail: <input type="email" id="email"
            value="careers@geeksforgeeks.org">
 
    <button onclick="myGeeks()">
        Click Here!
    </button>
     
    <p id="GFG"></p>
 
     
    <!-- Script to access input element with
            type email attribute -->
    <script>
        function myGeeks() {
            var em = document.getElementById("email").value;
            document.getElementById("GFG").innerHTML = em;
        }
    </script>
</body>
 
</html>                   

Output: 
Before click on the button: 
 



After click on the button: 
 

Example 2: This example uses document.createElement() method to create <input> element with type=”email” attribute.  

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        HTML DOM Input Email Object
    </title>
</head>   
 
<body>
 
    <h1> GeeksforGeeks</h1>
 
    <h2>DOM Input Email Object</h2>
 
    <button onclick="myGeeks()">
        Click Here!
    </button>
     
    <!-- script to create input element of
        type email attribute -->
    <script>
        function myGeeks() {
             
            /* Create an input element */
            var x = document.createElement("INPUT");
             
            /* Set the type attribute */
            x.setAttribute("type", "email");
             
            /* Set the value to type attribute */
            x.setAttribute("value", " careers@geeksforgeeks.org");
             
            /* Append the element to body tag */
            document.body.appendChild(x);
        }
    </script>
</body>
 
</html>                   

Output: 
Before click on the button: 
 

After click on the button: 
 

Supported Browsers

  • Google Chrome
  • Internet Explorer (after IE 9)
  • Firefox
  • Opera

 

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :