- Instant help with your JavaScript coding problems

Detect Ctrl + click in JavaScript

Question:
How to detect Ctrl + click in JavaScript?
Answer:
let element = document.getElementById('myElement');

element.addEventListener('click', evt => {
    if (evt.ctrlKey) {
        alert('Ctrl + click');
    }
});
Description:

The MouseEvent.ctrlKey read-only property is a Boolean that indicates whether the ctrl key was pressed or not when a given mouse event occurs.

The property returns a Boolean, where true indicates that the key is pressed, and false indicates that the key is not pressed.

Share "How to detect Ctrl + click in JavaScript?"
Tags:
ctrl+click, check ctrl status, click event, keypress
Technical term:
Detect Ctrl + click in JavaScript