Skip to content
Related Articles

Related Articles

jQuery event.metaKey Property

View Discussion
Improve Article
Save Article
  • Last Updated : 08 Jul, 2020
View Discussion
Improve Article
Save Article

The event.metaKey property in jQuery is used to identify whether the meta key is pressed or not. There are two examples discussed below.
Syntax:

event.metaKey

Return Value: It returns “true” if the key is meta key else it returns “false”.

Example 1: In this example, type in the <input> element and see the result.




<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        jQuery event.metaKey Property
    </title>
  
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
      
    <p id="GFG_UP"></p>
  
    <input type="text" 
        onkeydown="Geeks(event)" />
  
    <p id="GFG_DOWN"></p>
  
    <script>
        var elUp = document.getElementById("GFG_UP");
        var elDown = document.getElementById("GFG_DOWN");
        elUp.innerHTML = "JQuery | event.metaKey property";
  
        function Geeks(event) {
            if (event.metaKey) {
                elDown.innerHTML = 
                    "The META key was pressed!";
            } else {
                elDown.innerHTML = 
                    "The META key was NOT pressed!";
            }
        
    </script>
</body>
  
</html>

Output:

Example 2: Press any button from anywhere in the document and see the result.




<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        JQuery event.metaKey Property
    </title>
  
    <script src=
    </script>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
      
    <p id="GFG_UP"></p>
  
    <p id="GFG_DOWN"></p>
  
    <script>
        var elUp = document.getElementById("GFG_UP");
        var elDown = document.getElementById("GFG_DOWN");
        elUp.innerHTML = "JQuery | event.metaKey property";
          
        $('html').click(function (event) {
            if (event.metaKey) {
                elDown.innerHTML = 
                    "The META key was pressed!";
            } else {
                elDown.innerHTML = 
                    "The META key was NOT pressed!";
            }
        }); 
    </script>
</body>
  
</html>

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!