Javascript DOM HTML Element accessKey Property set

Introduction

The accessKey property sets or gets the accesskey attribute of an element.

The following code sets the access key of a link:

In this example, the keyboard key "w" is for java2s.com.

View in separate window

<!DOCTYPE html>
<html>
<body>

<a id="myLink" href="https://www.java2s.com/">Examples</a><br>
<script>
document.getElementById("myLink").accessKey = "w";
</script>/*from   w  w w  .ja  va  2  s.c  o m*/

</body>
</html>

The accesskey attribute specifies a shortcut key to activate/focus an element.

The way of accessing the shortcut key is varying in different browsers:

Browser Windows Linux Mac
Internet Explorer[Alt] + accesskeyN/A N/A
Chrome [Alt] + accesskey[Alt] + accesskey [Control] [Option] + accesskey
Firefox [Alt] [Shift] + accesskey[Alt] [Shift] + accesskey [Control] [Option] + accesskey
Safari [Alt] + accesskey N/A [Control] [Option] + accesskey



PreviousNext

Related