The HTML ButtonElement.accessKey property is used to return a DOMString which is a single character representing the accessKey in the given button.
Syntax:
ButtonElement.accessKey
Return Value: This property returns a DOMString which is a single character representing the accessKey to the given button.
Example 1:
HTML
< h1 style = "color:green" >neveropen</ h1 > < h2 >HTMLButtonElement.accessKey property</ h2 > < button accessKey = 'g' onclick = "gfg()" > Click </ button > < p id = "gfg" ></ p > < script type = "text/javascript" > function gfg() { var a = document.getElementsByTagName("button"); document.getElementById("gfg").innerHTML = 'accessKey is : '+a[0].accessKey; } </ script > |
Output:
Example 2:
HTML
< h1 style = "color:green" >neveropen</ h1 > < h2 >HTMLButtonElement.accessKey property</ h2 > < button accessKey = 'k' onclick = "gfg()" > Click </ button > < script > function gfg() { var a = document.getElementsByTagName("button"); document.write('accessKey is : ', a[0].accessKey); } </ script > |
Output:
Supported Browsers:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
- Edge
Reference: https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement