The HTML DOM accessKey property is used to set the accessKey attribute of an element. However, the accesskey attribute in HTML is used to set a shortcut key to activate or focus on an element.
Following is the syntax to set the accessKey property −
HTMLElementObject.accessKey = char
Above, char is the shortcut key.
Following is the syntax to return the accessKey property −
HTMLElementObject.accessKey
On Windows, set the access key for different browsers −
| Web Browser | Windows OS |
|---|---|
| Safari | [Alt] + accesskey |
| Chrome | [Alt] + accesskey |
| Firefox | Alt] [Shift] + accesskey |
Let us now see an example to implement the accesskey property on Chrome web browser on Windows −
Example
<!DOCTYPE html>
<html>
<body>
<a id="myid" accesskey="g" href="https://www.google.com/">Google</a>
<p>Get the accessKey</p>
<button onclick="display()">Click and display the accesskey</button>
<p id="pid"></p>
<script>
function display() {
var a = document.getElementById("myid").accessKey;
document.getElementById("pid").innerHTML = a;
}
</script>
</body>
</html>Output

Click on the above button to display the accessKey −
