In Bootstrap 3, there are 4 states; extra small devices, small devices, medium devices, and large devices. How can I know the website is currently at which state with jQuery? So that I can do some processing like when it is in extra small devices, then run this function.
Thanks.
I made some changes to this for bootstrap 3, try this"
function findBootstrapEnvironment() {
    var envs = ["ExtraSmall", "Small", "Medium", "Large"];
    var envValues = ["xs", "sm", "md", "lg"];
    var $el = $('<div>');
    $el.appendTo($('body'));
    for (var i = envValues.length - 1; i >= 0; i--) {
        var envVal = envValues[i];
        $el.addClass('hidden-'+envVal);
        if ($el.is(':hidden')) {
            $el.remove();
            return envs[i]
        }
    };
}
                        Following @Khurshid's answer (which works perfectly well) I've written a native JavaScript implementation which is significantly faster:
function findBootstrapEnvironment() {
    var envs = ["xs", "sm", "md", "lg"],    
        doc = window.document,
        temp = doc.createElement("div");
    doc.body.appendChild(temp);
    for (var i = envs.length - 1; i >= 0; i--) {
        var env = envs[i];
        temp.className = "hidden-" + env;
        if (temp.offsetParent === null) {
            doc.body.removeChild(temp);
            return env;
        }
    }
    return "";
}
                        I had to do something similiar for the medium size.
The media query for the extra small is up to 480px;
so you can say something like:
if($(document).width > 480)
{
  //Do Something
}
                        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