The DOM accessKey property is used to set or return the accesskey attribute of an element.
Syntax :
- For Set the accessKey :
HTMLElementObject.accessKey = value
- For Return the accessKey :
HTMLElementObject.accessKey
Value :
- character: Character that is used to specify the shortcut-key.
Return Value : This will return the selected element with the attached accessKey.
Example-1: This example shows that how a accessKey is attached to a selected element.
<!DOCTYPE html> <html> <head> <title> HTML | DOM accessKey Property </title> <style> body { width: 90%; color: green; border: 2px solid green; height: 40%; font-weight: bold; text-align: center; padding: 30px; font-size: 20px; } </style> </head> <body> <a id="main" GeeksforGeeks </a> <br> <p> This example show how to attach an accessKey to a selected element. </p> <script> document.getElementById("main").accessKey = "g"; </script> </body> </html> |
Output :
Before Click:

After Click:

Example-2: This example shows that how check that which accessKey is attached to a selected element.
<!DOCTYPE html> <html> <head> <title> HTML | DOM accessKey Property </title> <style> div { width: 80%; color: green; border: 2px solid green; height: 40%; font-weight: bold; text-align: center; padding: 30px; font-size: 20px; } #p1 { width: 130px; height: 20px; display: block; background-color: lightgrey; float: right; margin-top: -10px; padding: 5px; } #d { color: black; } </style> </head> <body> <div> <a id="main" accesskey="g" GeeksforGeeks </a> <p> Click the button to get the accesskey of the link. </p> <p id="p1">Answer : <span id="d"> </span> </p> </div> <br> <input type="button" onclick="myFunction()" value="Click Me.!" /> <script> function myFunction() { var gfg = document.getElementById("main").accessKey; document.getElementById("d").innerHTML = gfg; } </script> </body> </html> |
Output:
Before Click:

After Click:

Note: The shortcut varies from browsers to browsers.
- Mozilla Firefiix: ALT + SHIFT + accesskey
- Google Chrome: ALT + accesskey
- Opera 15+: ALT + accesskey
- Safari: ALT + accesskey
- IE: ALT + accesskey
Supported Browser: The browser supported by DOM accessKey Property are listed below.
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | accesskey Attribute
- HTML | DOM name Property
- HTML | DOM id Property
- HTML | DOM dir Property
- HTML | DOM URL Property
- HTML | DOM value Property
- HTML | DOM Map name Property
- HTML | DOM Bdo dir Property
- HTML | DOM specified Property
- HTML | DOM li value Property
- HTML | DOM isId Property
- HTML | DOM IFrame src Property
- HTML | DOM IFrame name Property
- HTML | DOM Option value Property
- HTML | DOM Select value Property
- HTML | DOM del cite Property
- HTML | DOM del dateTime Property
- HTML | DOM cookie Property
- HTML | DOM namespaceURI property
- HTML | DOM Output name Property
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 : nidhi_biet


