Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at https://viewsourceconf.org

event.altKey Redirect 1

« DOM Reference

Summary

Indicates whether the ALT key was pressed when the event fired.

Syntax

event.altKey

Examples

var bool = event.altKey;

bool contains true or false, depending on whether the alt key was held down or not, when the event fired.

<html>
<head>
<title>altKey example</title>

<script type="text/javascript">

function showChar(e){
  alert(
    "Key Pressed: " + String.fromCharCode(e.charCode) + "\n"
    + "charCode: " + e.charCode + "\n"
    + "ALT key pressed: " + e.altKey + "\n"
  );
}

</script>
</head>

<body onkeypress="showChar(event);">
<p>
Press any character key,
with or without holding down the ALT key.<br />
You can also use the SHIFT key together with the ALT key.
</p>
</body>
</html>

Specification

DOM Level 2 Events - property of MouseEvent object

Document Tags and Contributors

 Last updated by: Sheppy,