You are here: Reference > JavaScript > client-side > event handling > properties > altKey (event)

altKey property (event)

Browser support:
Sets or retrieves a Boolean value that indicates whether the left or right ALT key was down at the time when the event occurred.
In Internet Explorer, use the altLeft property to detect whether the left or right ALT key is down.
For CTRL and SHIFT keys, use the ctrlKey and shiftKey properties.

Syntax:

object.altKey;
You can find the related objects in the Supported by objects section below.
The altKey property is read-only in, except if the event object is created with the createEventObject method when it is read/write.

Possible values:

Boolean that sets or retrieves the state of the ALT key.
One of the following values:
false
ALT key is up.
true
ALT key is down.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the altKey property:
<head>
    <script type="text/javascript">
        function GetAltState (event) {
            if (event.altKey) {
                alert ("ALT key is down.");
            }
            else {
                alert ("ALT key is up.");
            }
        }
    </script>
</head>
<body>
    Press and hold down the ALT key before you click on the button.
    <br />
    <button onclick="GetAltState (event);">Get ALT key state!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content