jQuery event.metaKey

Beginner
5 min read
Updated: Oct 2026
5 examples
Live preview

What Is event.metaKey?

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 ().

Remember
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
NeedUse
Meta / Command / Windows held?event.metaKey
Control held?event.ctrlKey
Shift held?event.shiftKey
Alt / Option held?event.altKey
Which key / buttonevent.which
Bind handlers.on("click", fn)

How to Use event.metaKey

Read it on the event object inside any mouse or keyboard handler.

  1. Bind a handler with .on("click", …) or .on("keydown", …).
  2. Accept the event argument in the handler.
  3. Read event.metaKey (no call — it is a property).
  4. Branch: if true, Meta/Command/Windows was held.
  5. For cross-platform shortcuts, also check event.ctrlKey when needed.
PieceRequired?Role
eventYesjQuery event object in the handler
metaKey—Boolean: Meta held or not
ArgumentsN/AProperty — not a function
ctrlKey etc.OptionalOther modifiers on the same event

Pseudocode

Pseudocode
target.on("click", handler)

when click fires:
    browser sets event.metaKey from keyboard state
    if event.metaKey is true:
        Meta / Command / Windows was held
    else:
        Meta was not held

// Common cross-platform pattern:
if event.metaKey OR event.ctrlKey:
    treat as "primary modifier" shortcut

Cheat Sheet

Keep these facts handy while reading modifier keys.

TopicDetail
TypeBoolean property (not a method)
SincejQuery 1.0.4
MacCommand (⌘)
WindowsWindows key
Official demo$("#display").text(event.metaKey)
Read-onlyReflects browser state; do not assign
Cross-platformmetaKey || ctrlKey
Official docsapi.jquery.com/event.metaKey/

Live Preview

Click the target. Hold Command (Mac) or the Windows key and click again — same idea as the official jQuery API demo.

Demo

Shows event.metaKey as true or false.

Display
Click above (try with Meta held).

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

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.
  4. Try Meta. Hold Command / Windows and click again for true.

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.
  4. Plain click. Handle same-tab intent without Meta/Ctrl.

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.
  4. Debug. Print all four when shortcuts feel “wrong.”

Example 4 — Multi-Select with Meta/Ctrl

Plain click selects one item; Meta/Ctrl click toggles without clearing others.

jQuery
var selected = [];

$("#list").on("click", "button", function (event) {
  var name = $(this).text();
  if (!event.metaKey && !event.ctrlKey) {
    selected = [name];
  } else {
    var i = selected.indexOf(name);
    if (i === -1) selected.push(name);
    else selected.splice(i, 1);
  }
  $("#out").text("Selected: " + selected.join(", "));
});
Try It Yourself

How It Works

  1. Plain click. Replace the selection with one item.
  2. Meta/Ctrl. Toggle that item in the list.
  3. Cross-platform. Check both modifiers in one condition.
  4. Show. Print the selected names — no CSS required.

Example 5 — Keyboard: metaKey + S

Detect a Meta+S chord on keydown.

jQuery
$(document).on("keydown", function (event) {
  if (event.metaKey && event.key === "s") {
    event.preventDefault();
    $("#out").text("Save shortcut — metaKey: " + event.metaKey);
  }
});
Try It Yourself

How It Works

  1. Listen. Use keydown on document.
  2. Chord. Require metaKey and key === "s".
  3. Prevent default. Stop the browser Save dialog when you handle it.
  4. Note. On Windows, many apps use Ctrl+S — add || event.ctrlKey if needed.

Edge Cases & Pitfalls

Watch for these when using event.metaKey.

property

Not a method

Write event.metaKey, not event.metaKey().

OS

Meta ≠ Ctrl on Windows

Ctrl+click sets ctrlKey. Use metaKey || ctrlKey for shared shortcuts.

read-only

Cannot assign it

Setting event.metaKey = true does not simulate holding Meta for the browser.

touch

Touch devices

Phones and tablets usually have no Meta key — metaKey stays false.

Browser Support

event.metaKey is a jQuery event-object property available since 1.0.4. Browsers map Meta to Command (Mac) or the Windows key (PC). Works wherever your loaded jQuery version runs.

✓ Stable · jQuery 1.0.4+

event.metaKey

Supported in jQuery 1.0.4–3.x. Prefer jQuery 3.x with .on() handlers. Read the Boolean on click, mousedown, keydown, and related events.

100% With jQuery 1.0.4+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
metaKey jQuery 1.0.4+

Bottom line: Safe for production. Remember platform mapping: Command on Mac, Windows key on PC; use metaKey || ctrlKey for shared shortcuts.

Performance Notes

ApproachCostBest for
Read event.metaKeyFreeOne Boolean check in a handler
metaKey || ctrlKeyFreeCross-platform shortcut branches
Document keydownCheapGlobal chords; keep the handler tiny

Modifier reads are free. Cost comes from what you do when the flag is true — keep shortcut handlers short.

Key Takeaways

  • Role: Boolean — was Meta held when the event fired?
  • Platform: Command on Mac, Windows key on PC.
  • Official: $("#display").text(event.metaKey).
  • Cross-OS: often metaKey || ctrlKey for shared shortcuts.

One line: event.metaKey answers “was Command / Windows held for this event?”

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

Identify which key or mouse button produced the event.

event.which tutorial →

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