JavaScript, Browser

Checks if touch events are supported.

  • Check if 'ontouchstart' exists in window.
const supportsTouchEvents = () =>
  window && 'ontouchstart' in window;
supportsTouchEvents(); // true

Recommended snippets

  • onUserInputChange

    JavaScript, Browser

    Runs the callback whenever the user input type changes (mouse or touch).

  • If you need to check if Caps Lock is on when the user is typing in the browser, JavaScript's got you covered.

  • copyToClipboard

    JavaScript, Browser

    Copies a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).