If you are wanting to redirect a user to your mobile site you would use this:
if (screen.width <= 768) {
window.location = "mobile.html";
}
If you want to find out if its touch screen and less than 768px I think you could use this:
var is_touch_device = 'ontouchstart' in document.documentElement;
var viewport = $(window).width()
if (is_touch_device == true && viewport < 768) {
(Code goes here)
}