Open In App

HTML DOM Keygen name Property

Improve
Improve
Like Article
Like
Save
Share
Report

The keygen name property in HTML DOM is used to set or return the value of the name attribute of the <keygen> element. The name attribute is used to specify the name of the keygen element.

Syntax:

  • It returns the name property.

    keygenObject.name
  • It sets the name property.

    keygenObject.name = keygenName

Return Values: It returns a string value that represents the name of the keygen element.

Property Value: It contains a string value that specifies the name of the keygen element. 

Example: The below HTML code returns and sets the name of the keygen element.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h2>HTML DOM Keygen name Property</h2>
    <br>
  
    <form id="myGeeks">
        Username: <input type="text" 
                         name="uname">
        <br><br> Encryption:
        <keygen id="Geeks" form="myGeeks"
                name="secure" autofocus>
        <input type="submit">
    </form>
    <br>
    <button onclick="display()">Display</button>
    <button onclick="set_name()">Set</button>
  
    <p id="test"></p>
  
  
    <script>
        function display() {
            var d = document.getElementById("Geeks").name;
            alert(
              "The name of the keygen is: " + d);
        }
  
        function set_name() {
            var g = document.getElementById(
                "Geeks").name = "myKeygen";
  
            alert(
                "The name of the Keygen was changed to " + g
            );
        }
    </script>
</body>
  
</html>


Output:

Supported Browsers:

  • Google Chrome
  • Opera
  • Safari
  • Firefox


Last Updated : 28 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads