You need to use a simple window.matchMedia(). How can Detect mobile or tablet using jQuery?.
The following code will help you to Detect Mobile Device using jQuery.
<script>
$(document).ready(function(){
if(window.matchMedia(“(max-width: 767px)”).matches){
alert(“Mobile Device.”);
} else {
alert(“Tablet or Desktop.”);
}
});
</script>