Open In App

How to check whether the META key pressed when event is fired using jQuery ?

jQuery is a feature-rich JavaScript library. It is a fast and most used JavaScript library. Before using jQuery you must have a basic knowledge of HTML, CSS, and JavaScript.

In this article, we will learn about how you can check whether the META key was pressed when the event fired JQuery.



META key: It is a special key that is located next to the space bar on the keyboard. The different operating system, it is located at different location example – 

event.metaKey: It will return a boolean value (true or false) that indicates whether the META key was pressed at the time the event fired or not. 



Example: In this example, we are using the above-explained method.




<!doctype html>
<html lang="en">
<head>
    <style>
        h1 {
            color: green;
        }
 
        body {
            background-color: lightgreen;
            text-align: center;
        }
 
        div {
            padding: 20px;
        }
 
        p {
            font-size: 25px;
        }
 
        button {
            background-color: #4CAF50;
            /* Green */
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
        }
    </style>
 
    <script src=
    </script>
</head>
 
<body>
    <h1>GeeksForGeeks</h1>
 
    <p>
        Click here to check whether
        Meta key was pressed of not.
    </p>
 
    <button value="Test" name="Test" id="check">
        click Here!!
    </button>
 
    <h1 style="color:black;" id="display">
          ****
    </h1>
 
    <script>
        $("#check").click(function (event) {
            $("#display").text(event.metaKey);
        });
    </script>
</body>
</html>

Output:

 


Article Tags :