Thursday, September 4, 2025
HomeLanguagesJavascriptJavaScript MouseEvent altKey Property

JavaScript MouseEvent altKey Property

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

Syntax: 

event.altKey

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

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

Example: In this example, we will see the example of MouseEvent altKey property.

html




<body style="text-align:center;">
  
    <h1 style="color:green;">
        neveropen
    </h1>
  
    <h2>
        mouseEvent altKey Property
    </h2>
  
    <button onclick="geek (event);">Get Alt key state!</button>
    <p id="gfg"></p>
    <script>
        function geek(event) {
            if (event.altKey) {
                document.getElementById("gfg")
                        .innerHTML = "Alt key is pressed.";
            } else {
                document.getElementById("gfg")
                        .innerHTML ="Alt key is not pressed.";
            }
        }
    </script>
</body>


Output: 

 

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

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6717 POSTS0 COMMENTS