Apr 6, 2026
Handling the click event is common in web development. Tablets and phones, do not technically have click but will respond to the event at the end of a touch. Capturing touchstart can lead to improved perceived performance on these devices. Here is how to handle both.
const touch = ( 'ontouchstart' in document.documentElement ) ? 'touchstart' : 'click';
const button = document.querySelector( 'button' );
button.addEventListener( touch, () => console.log( 'Do something' ) );
Back to Notes