Skip to content
Related Articles

Related Articles

Javascript | MouseEvent altKey Property

Improve Article
Save Article
  • Last Updated : 26 Mar, 2021
Improve Article
Save Article

The mouseEvent altKey property is used to define whether the alt key is pressed or not. It is a boolean value. When alt key is pressed then onclick of the mouse buttons it returns true and if it is not pressed then it returns false. 



Return Value: It returns a boolean value indicating whether alt key is pressed or not. 

  • true: it indicates alt key is pressed
  • false: it indicates alt key is not pressed

Example : 


<!DOCTYPE html>
<body style="text-align:center;">
    <h1 style="color:green;">
        mouseEvent altKey Property
    <button onclick="geek (event);">Get Alt key state!</button>
        function geek(event) {
            if (event.altKey) {
                alert("Alt key is pressed.");
            } else {
                alert("Alt key is not pressed.");

Clicking button (Alt key is not pressed): 


Clicking button (Alt key is pressed): 


Supported Browsers: The browser supported by  mouseEvent altKey Property are listed below: 

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!