I have function that works on click
$('#test').click(function(e){
// some code
});
How can I check if the test
element clicked or touched?
You could use one event for the both then detect type of the event triggered :
$('#test').on('touchend click',function(e){
if(e.type=='click')
alert('click triggered');
else
alert('touch triggered');
});
Hope this helps.
$('#test').on('touchend click',function(e){
if(e.type=='click')
alert('click triggered');
else
alert('touch triggered');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="test">TEST</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With