MDN self-hosted library · e01.org

MouseEvent: altKey property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<p>Click anywhere to test the <code>altKey</code> property.</p>
<p id="log"></p>
js
let log = document.querySelector("#log");
document.addEventListener("click", logKey);

function logKey(e) {
  log.textContent = `The alt key is pressed: ${e.altKey}`;
}