Open In App
Related Articles

HTML | DOM Input Email Object

Improve Article
Improve
Save Article
Save
Like Article
Like

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.

Methods 

  • select () : It is used to select the content of a Input Email text 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 5
  • Edge 12
  • Firefox
  • Opera 11
  • Safari

 


Last Updated : 25 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials