jQuery event.metaKey

Beginner
5 min read
Updated: Nov 2026
3 examples
Events

Definition

A Boolean property: true if the META key was pressed when the event fired, otherwise false. Added in jQuery 1.0.4. It is a property — not a method — so do not call it with ().

Syntax

Start with these common calls. Keep them short and readable.

jQuery
event.metaKey  // Boolean property — no parentheses

// Official idea
$("#checkMetaKey").on("click", function (event) {
  $("#display").text(event.metaKey); // true or false
});

// Mac: Command (⌘)  ·  Windows: Windows key
// Cross-platform "primary" shortcut: metaKey || ctrlKey
CallWhat it does
event.metaKeyLearn jQuery event.metaKey: detect the Meta modifier (Command on Mac, Windows key on PC) on click and keyboard events, official true/false demo, Cmd+click patterns, modifier comparison, examples, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Bind a handler with .on("click", …) or .on("keydown", …).
Step 2Accept the event argument in the handler.
Step 3Read event.metaKey (no call — it is a property).

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.

jQuery Examples

Example 1 — Official: Display metaKey on Click

Show true or false when the target is clicked.

jQuery
$("#checkMetaKey").on("click", function (event) {
  $("#display").text(event.metaKey);
});
Try It Yourself

How It Works

  1. Bind. Attach a click handler to the target.
  2. Read. Use event.metaKey — no parentheses.
  3. Show. Put the Boolean into #display.

Example 2 — Cmd/Ctrl+Click Opens in a New Tab

Mirror desktop “open in new tab” with Meta or Control.

jQuery
$("a.doc-link").on("click", function (event) {
  if (event.metaKey || event.ctrlKey) {
    event.preventDefault();
    window.open(this.href, "_blank");
    $("#out").text("Opened in new tab (meta/ctrl).");
    return;
  }
  event.preventDefault();
  $("#out").text("Normal click → same-tab intent: " + this.href);
});
Try It Yourself

How It Works

  1. Check. metaKey || ctrlKey covers Mac and Windows.
  2. Prevent default. Stop the browser’s normal navigation first.
  3. New tab. Use window.open when the modifier is held.

Example 3 — All Four Modifier Flags

Log metaKey, ctrlKey, shiftKey, and altKey on each click.

jQuery
$("#panel").on("click", function (event) {
  $("#out").text(
    "metaKey: " + event.metaKey + "\\n" +
    "ctrlKey: " + event.ctrlKey + "\\n" +
    "shiftKey: " + event.shiftKey + "\\n" +
    "altKey: " + event.altKey
  );
});
Try It Yourself

How It Works

  1. Four Booleans. Each modifier is independent.
  2. Combine. Shift+Command can make two flags true.
  3. Platform. Windows Ctrl often sets ctrlKey, not metaKey.

Frequently Asked Questions

event.metaKey is a Boolean property on the jQuery event object. It is true when the META modifier key was pressed when the event fired, and false otherwise. Available since jQuery 1.0.4.
On Macintosh keyboards, metaKey maps to the Command key (⌘). On Windows keyboards, metaKey maps to the Windows key. The property name is always metaKey.
They report different modifiers. On Mac, Command-click often sets metaKey; Ctrl-click sets ctrlKey. On Windows, Ctrl+click sets ctrlKey; the Windows key may set metaKey. Do not assume metaKey is the primary shortcut key on every OS.
Mouse events such as click, mousedown, and mouseup expose metaKey when Meta/Command/Windows is held. Keyboard events such as keydown and keyup also expose it alongside key and other modifiers.
No. metaKey is read-only — it reflects keyboard state when the browser dispatched the event. You cannot flip it to simulate a modifier.
Many apps use (event.metaKey || event.ctrlKey) for “primary modifier + click/key” so Mac Command and Windows Ctrl behave similarly. Use metaKey alone when you specifically need the Meta/Command/Windows key.

Next: event.which Property

Identify which key or mouse button produced the event.

event.which Property tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful