Tristan Tristan - 1 year ago 83
Javascript Question

How do I apply jquery for mobile only?

I need to apply the following jquery for mobile browsers only:


This is to reorder the position of bootstrap columns.

How do I do this? Does it need to be wrapped in something?

Answer Source

It always very hard to detect whether its a mobile device's browser or a laptop with a touch screen. So instead of detecting that if you are concern about the screen size then i will recommend you to detect the screen size and if its below certain level(lets say below 481px) then we will assume that its a mobile screen and will execute your needed code as follows:

$(document).ready(function () {
    $(window).on("resize", function (e) {


    function checkScreenSize(){
        var newWindowWidth = $(window).width();
        if (newWindowWidth < 481) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download