jQuery event.metaKey

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Event object · jQuery 1.0.4+

What You’ll Learn

event.metaKey is a Boolean property that tells you whether the Meta modifier was held when the event fired — Command (⌘) on Mac, Windows key on PC. This tutorial covers the official click demo, Cmd+click links, modifier key comparisons, multi-select UI, and keyboard handlers.

01

Property

event.metaKey

02

Returns

Boolean

03

Official

true / false

04

Mac

Command ⌘

05

Windows

Windows key

06

Since 1.0.4

Read-only

Introduction

Many user actions combine a pointer or key event with a modifier key — Command-click to open a link in a new tab, Shift-click to extend a selection, Ctrl/Cmd shortcuts in editors. The browser exposes which modifiers were down through properties on the event object.

event.metaKey specifically reports the META key. jQuery passes it through on its normalized event object since version 1.0.4. The official demo displays true or false when you click while holding or releasing the Meta key.

Understanding event.metaKey

This property answers one question: was the Meta modifier held when this event fired?

  • Meta not pressedevent.metaKey is false.
  • Meta heldtrue for that click, mousedown, keydown, or related dispatch.
  • Read-only — not a function; do not call with parentheses.
  • Platform mapping — Mac Command and Windows key both surface as metaKey in supporting browsers.
💡
Beginner Tip

For cross-platform “primary shortcut” behavior (open in new tab, save, etc.), many tutorials use event.metaKey || event.ctrlKey. Use metaKey alone when you specifically need the Meta/Command/Windows key state.

📝 Syntax

Official jQuery API form (since 1.0.4) — a property, not a method:

jQuery
event.metaKey

// typical pattern:
$( "#target" ).on( "click", function ( event ) {
  if ( event.metaKey ) {
    // Meta / Command / Windows key was held
  }
});

Parameters

  • NonemetaKey is a property, not a function.

Return value

  • Booleantrue if the META key was pressed when the event fired; otherwise false.

Official jQuery API example

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

⚡ Quick Reference

PropertyModifierTypical key
event.metaKeyMETA⌘ Command / Windows
event.ctrlKeyControlCtrl
event.shiftKeyShiftShift
event.altKeyAltAlt / Option
Cross-platform shortcutmetaKey || ctrlKeyCmd or Ctrl

📋 metaKey vs ctrlKey vs shiftKey vs altKey

Four read-only Boolean properties — each reports a different modifier held during the event.

metaKey
event.metaKey

Command ⌘ / Windows key

ctrlKey
event.ctrlKey

Control key

shiftKey
event.shiftKey

Shift key

altKey
event.altKey

Alt / Option key

Examples Gallery

Example 1 follows the official jQuery demo. Examples 2–5 cover Cmd+click links, all modifiers, multi-select lists, and keyboard events.

📚 Official jQuery Demo

Click and read true or false from event.metaKey.

Example 1 — Official Demo: display metaKey on click

Official jQuery demo — click the target and show whether the Meta key was held (true or false).

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

How It Works

The browser sets metaKey on the event before your handler runs. jQuery forwards the same Boolean on its event object — no extra setup required.

Example 2 — Cmd+click: open link in new tab

Intercept link clicks — when metaKey (or ctrlKey for cross-platform) is true, open in a new tab instead of navigating in place.

jQuery
$( "a.doc-link" ).on( "click", function ( event ) {
  if ( event.metaKey || event.ctrlKey ) {
    event.preventDefault();
    window.open( this.href, "_blank" );
    return;
  }
  // normal navigation follows href
});
Try It Yourself

How It Works

Desktop browsers use Meta+click (Mac) or Ctrl+click (Windows/Linux) for “open in new tab.” Checking metaKey lets custom link handlers mirror that UX.

📈 Practical Patterns

Modifier dashboard, list selection, and keyboard events.

Example 3 — Modifier dashboard on click

Log all four modifier properties on each click to see which keys were held.

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

How It Works

Modifier properties are independent Booleans — more than one can be true at once (e.g. Shift+Command+click).

Example 4 — Multi-select list: metaKey toggles items

Plain click selects one row; metaKey click toggles a row without clearing others (desktop file-picker pattern).

jQuery
$( "#list" ).on( "click", "li", function ( event ) {
  if ( !event.metaKey && !event.ctrlKey ) {
    $( "#list li" ).removeClass( "selected" );
  }
  $( this ).toggleClass( "selected" );
});
Try It Yourself

How It Works

metaKey signals additive selection. Pairing with ctrlKey covers Mac and Windows conventions in one condition.

Example 5 — Keyboard: metaKey on keydown

Listen for keydown and show when the Meta key participates in a chord (e.g. holding Command while pressing another key).

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

How It Works

Keyboard events expose the same modifier properties as mouse events. metaKey stays true while the Meta/Command key is held during the keydown dispatch.

🚀 Common Use Cases

  • Cmd+click links — open URLs in a new tab when metaKey is true.
  • Multi-select lists — additive selection with Meta/Ctrl held.
  • Canvas / diagram tools — Meta+drag for alternate tool modes.
  • Custom shortcuts — detect Meta+key chords in keydown handlers.
  • Analytics — tag events when users hold modifiers during clicks.
  • Accessibility docs — display platform-specific shortcut labels using modifier state.

🧠 How metaKey Works

1

User input

User clicks or presses a key while holding Command, Windows key, or other modifiers.

Input
2

Browser builds event

Native event gets metaKey: true/false plus sibling modifier flags.

Native
3

jQuery handler

Your .on() callback receives the normalized event — read event.metaKey.

Handler
4

Branch your UI

Open new tabs, extend selection, or run shortcuts based on the Boolean.

📝 Notes

  • Available since jQuery 1.0.4 — a Boolean property, not a method.
  • Read-only — reflects keyboard state at dispatch time.
  • Mac Command (⌘) sets metaKey; Windows Windows key sets metaKey in supporting browsers.
  • Do not confuse with ctrlKey — on Mac, Control and Command are different keys.
  • Works on mouse and keyboard events that expose modifier state (e.g. click, keydown).
  • For cross-platform primary shortcuts, consider event.metaKey || event.ctrlKey.

Browser Support

event.metaKey is forwarded on jQuery’s event object since jQuery 1.0.4+. Underlying support comes from the DOM MouseEvent and KeyboardEvent modifier properties — consistent across modern browsers jQuery targets.

jQuery 1.0.4+ · all browsers

jQuery event.metaKey

Detect the Meta modifier on events.

100% Universal
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 Boolean

Bottom line: Read event.metaKey in handlers — true when Command / Windows key was held.

Conclusion

event.metaKey tells you whether the Meta modifier was held when the event fired — Command on Mac, Windows key on PC. The official demo prints true or false on each click.

Use it for Cmd+click behavior, multi-select UIs, and keyboard shortcuts — and pair with ctrlKey when you need cross-platform parity.

💡 Best Practices

✅ Do

  • Read event.metaKey in click handlers for Cmd+click UX
  • Use metaKey || ctrlKey for cross-platform shortcut parity
  • Document shortcuts per platform in UI tooltips
  • Combine with shiftKey for range-selection patterns
  • Test on Mac and Windows hardware when modifiers matter

❌ Don’t

  • Call event.metaKey() with parentheses — it is a property
  • Assume metaKey means Ctrl on Windows — check both or test
  • Overwrite or assign to event.metaKey
  • Rely on metaKey alone for save/copy shortcuts on all OSes
  • Forget touch devices — modifiers apply to keyboard/mouse combos

Key Takeaways

Knowledge Unlocked

Five things to remember about metaKey

Detect the Meta modifier on jQuery events.

5
Core concepts
Mac 02

Command

⌘ on Mac

Map
demo 03

Official

true / false

Demo
link 04

Cmd+click

New tab

Use
ctrl 05

ctrlKey

Cross-platform

Pair

❓ Frequently Asked Questions

event.metaKey is a Boolean property on the jQuery event object. It is true when the META modifier key was pressed at the time 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 — check the platform or document the shortcut for users.
They report different modifier keys. On Mac, Command-click often sets metaKey while Ctrl-click sets ctrlKey. On Windows, Ctrl+click sets ctrlKey; the Windows key may set metaKey. Do not assume metaKey equals "primary shortcut key" on every OS — test or branch on both when needed.
Mouse events such as click, mousedown, and mouseup expose metaKey when the Meta/Command/Windows key is held. Keyboard events such as keydown and keyup also expose metaKey alongside key, code, 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; trigger real events or branch on the actual property value.
Many web apps use (event.metaKey || event.ctrlKey) for "primary modifier + click/key" shortcuts so Mac Command and Windows Ctrl behave similarly. metaKey alone is correct when you specifically need the Meta/Command/Windows key state.
Did you know?

The name metaKey comes from historical “Meta” keys on Lisp workstations. Apple mapped it to Command; browsers kept the property name for compatibility. jQuery has exposed it since 1.0.4 alongside ctrlKey, shiftKey, and altKey.

Next: event.which

Detect which key or mouse button was pressed with normalized event.which.

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.

6 people found this page helpful