Detecting Mobile Devices with JavaScript

Detection of mobile device concept of feature detection over browser detection, sometimes we need for knowing whether we are on mobile device or other Device. I thought out a simple way to detect the user was on a mobile device, then swap out the class name of an element.

Why we need to check user is on mobile device :

1.Targeting Mobile Devices
2.Testing Mobile Device Functionality in Different Browsers
3.Adding or Swapping elements for Mobile Devices
4.But for simple applications, the following code is useful.

Put this code in your script tag:



check user on the any of the supported mobile devices:



check for specific mobile device:



I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face – we are here to solve your problems.

I, Dayanand Saini,the founder and chief editor of,have been working as a software engineer from last 4+ years. It's my hobby to learn new things and implement on live environment.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 + 5 =

%d bloggers like this: