myButton.addEventListener("mousedown", (e) => {
// Touch event case handled above, don't change the style again on tap.
if (!e.sourceCapabilities.firesTouchEvents) myButton.classList.add("pressed");
});InputDeviceCapabilities API / notebook
InputDeviceCapabilities API
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.