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. For the different operating system, it is located at a different location example –
- Windows – The META key maps to the Windows key.
- Macintosh – the META key maps to the Command key (⌘).
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:
HTML
<!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:
Before clicking the button – There is only one button named ‘click me please!’.
After clicking the button – After clicking the button if you see true then it indicates that you did press a meta key but in case, you can notice that your output is false it indicates that you didn’t press any meta key.
Please Login to comment...