HTML DOM accessKey Property

HTMLWeb DevelopmentFront End Technology

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 BrowserWindows OS
Safari[Alt] + accesskey
Chrome[Alt] + accesskey
FirefoxAlt] [Shift] + accesskey

Let us now see an example to implement the accesskey property on Chrome web browser on Windows −

Example

 Live Demo

<!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 −

raja
Published on 21-Jun-2019 15:41:30
Advertisements