Element accessKey Property - Javascript DOM

Javascript examples for DOM:Element accessKey

Description

The accessKey property sets or gets the accesskey attribute of an element, which defines a shortcut key to activate/focus an element.

Set the accessKey property with the following Values

Value Description
character Sets the shortcut key to activate/focus the element

Return Value

A character from the keyboard

The following code shows how to Set the access key of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<a id="w3s" accesskey="w" href="https://www.java2s.com/">java2s.com</a>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {// ww  w .  j av  a  2s.c  om
    document.getElementById("w3s").accessKey = 's';
}
</script>

</body>
</html>

Related Tutorials