[Home] > Snippets  > Browser  > DOM  >  Check if the touch events are supported

Check if the touch events are supported

JavaScript

const touchSupported = () =>
'ontouchstart' in window || (window.DocumentTouch && document instanceof window.DocumentTouch)

TypeScript

const touchSupported = (): boolean =>
'ontouchstart' in window || (window as any)['DocumentTouch'] && document instanceof (window as any)['DocumentTouch']