JSFiddle - React, Tailwind, and code Playground
HTML
<div class="box1">Click</div>
<div class="box2">Touch</div>
CSS
.box1, .box2 {
width: 50vw;
height: 50vw;
background-color: #22aa99;
margin: 1em;
text-align: center;
color: white;
font-size: 5vw;
}
JavaScript
var clickEvent = ('ontouchstart' in document.documentElement ?
'touchstart' :
'click');
$('.box1').click(function() {
$(this).css({ backgroundColor: 'black' });
});
$('.box2').on(clickEvent, function() {
$(this).css({ backgroundColor: 'black' });
});