
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
jquery-detect-environment
Advanced tools
A lightweight jQuery plugin that dynamically adds CSS classes to the html tag
A lightweight jQuery plugin that dynamically adds CSS classes to the <html>
tag based on the device type, operating system, screen size, orientation, browser, internet connection, time of day, color scheme preference, and pixel density. This helps create responsive and adaptive designs easily.
The plugin automatically detects and adds classes for:
device-mobile
or device-desktop
os-windows
, os-macos
, os-linux
, os-android
, os-ios
width-xs
, width-sm
, width-md
, width-lg
, width-xl
orientation-portrait
or orientation-landscape
browser-chrome
, browser-firefox
, browser-safari
, browser-edge
status-online
or status-offline
time-morning
, time-afternoon
, time-evening
, time-night
prefers-dark-mode
or prefers-light-mode
pixel-ratio-1x
, pixel-ratio-2x
, or pixel-ratio-3x
Include jQuery in your project (if not already included):
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
Include the plugin script (choose between the full or minified version):
<script src="path/to/jquery.detect-environment.js"></script>
<script src="path/to/jquery.detect-environment.min.js"></script>
The plugin initializes automatically when the document is ready and dynamically adds classes to the <html>
tag. It also listens for window resize, orientation change, and network connection events to update classes in real-time.
$(document).ready(function() {
$('html').detectEnvironment();
});
The classes added to <html>
will update automatically, so you can use them directly in your CSS for responsive and adaptive design.
With this plugin, the <html>
tag might look like:
<html class="device-desktop os-windows width-lg orientation-landscape browser-chrome status-online time-afternoon prefers-light-mode pixel-ratio-2x">...</html>
Here are some sample classes and what they represent:
The plugin listens for the following events to update classes dynamically:
This project is licensed under the MIT License.
This portion of the README.md
file provides examples and explanations of the classes generated by the plugin, describes the events it listens for, and includes a brief note on the license. It’s designed to help users understand how to work with the classes generated by the plugin for responsive design.
FAQs
A lightweight jQuery plugin that dynamically adds CSS classes to the html tag
The npm package jquery-detect-environment receives a total of 4 weekly downloads. As such, jquery-detect-environment popularity was classified as not popular.
We found that jquery-detect-environment demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.