# jQuery 4.0.0 Documentation **Release Date:** January 17, 2026 **License:** MIT **20th Anniversary Release** --- ## Table of Contents 1. [Overview](#overview) 2. [Installation](#installation) 3. [Browser Support](#browser-support) 4. [Breaking Changes](#breaking-changes) 5. [New Features](#new-features) 6. [Migration Guide](#migration-guide) 7. [API Reference](#api-reference) --- ## Overview jQuery 4.0.0 marks a significant milestone—celebrating jQuery's 20th anniversary and the first major version release in nearly 10 years. This release modernizes the library by removing legacy browser support, adopting ES modules, and improving security features. ### Key Highlights - **Modernized codebase** migrated from AMD to ES modules - **Smaller bundle size** with improved slim build - **Enhanced security** with Trusted Types and CSP support - **Removed deprecated APIs** in favor of native JavaScript equivalents - **Updated browser support** dropping legacy browsers --- ## Installation ### CDN ```html ``` ### npm ```bash npm install jquery@4.0.0 ``` ### ES Module Import ```javascript // Full import import $ from 'jquery'; // Named import import { jQuery } from 'jquery'; ``` ### CommonJS ```javascript const $ = require('jquery'); ``` --- ## Browser Support ### Supported Browsers | Browser | Minimum Version | |---------|-----------------| | Chrome | Last 3 versions | | Firefox | Last 2 versions + ESR | | Safari | Last 3 versions | | Edge (Chromium) | Last 3 versions | | iOS Safari | Last 3 versions | | Android Chrome | Last 3 versions | ### Removed Support The following browsers are **no longer supported**: - Internet Explorer 10 and earlier (IE 11 support planned for removal in jQuery 5.0) - Edge Legacy (non-Chromium) - iOS versions older than the last 3 - Firefox versions older than the last 2 (except ESR) - Android Browser (AOSP) --- ## Breaking Changes ### 1. Removed Deprecated Utility Functions Several utility functions deprecated in previous versions have been removed. Use native JavaScript equivalents instead. | Removed Function | Native Replacement | |------------------|-------------------| | `jQuery.isArray()` | `Array.isArray()` | | `jQuery.parseJSON()` | `JSON.parse()` | | `jQuery.trim()` | `String.prototype.trim()` | | `jQuery.type()` | `typeof` / `instanceof` | | `jQuery.now()` | `Date.now()` | | `jQuery.isNumeric()` | `!isNaN(parseFloat(n)) && isFinite(n)` | | `jQuery.isFunction()` | `typeof fn === 'function'` | | `jQuery.isWindow()` | `obj != null && obj === obj.window` | #### Example Migration ```javascript // jQuery 3.x (deprecated) if ($.isArray(myVar)) { /* ... */ } if ($.isFunction(callback)) { /* ... */ } var trimmed = $.trim(userInput); var data = $.parseJSON(jsonString); var timestamp = $.now(); // jQuery 4.0 (use native) if (Array.isArray(myVar)) { /* ... */ } if (typeof callback === 'function') { /* ... */ } var trimmed = userInput.trim(); var data = JSON.parse(jsonString); var timestamp = Date.now(); ``` ### 2. Focus Event Order Change The focus-related event order now follows the W3C specification. ```javascript // jQuery 3.x order: // focusout → blur → focusin → focus // jQuery 4.0 order (W3C compliant): // blur → focusout → focus → focusin ``` #### Example: Observing Event Order ```javascript const $input = $('#myInput'); $input.on('blur', () => console.log('1. blur')); $input.on('focusout', () => console.log('2. focusout')); $input.on('focus', () => console.log('3. focus')); $input.on('focusin', () => console.log('4. focusin')); // When focus moves from #myInput to another element: // Output in jQuery 4.0: // 1. blur // 2. focusout // Then when new element receives focus: // 3. focus // 4. focusin ``` ### 3. Removed Array Methods from jQuery Prototype The `push`, `sort`, and `splice` methods have been removed from the jQuery prototype. ```javascript // jQuery 3.x $elements.push(newElement); $elements.sort(compareFn); $elements.splice(0, 1); // jQuery 4.0 [].push.call($elements, newElement); [].sort.call($elements, compareFn); [].splice.call($elements, 0, 1); // Or convert to array first const elemArray = $elements.toArray(); elemArray.push(newElement); ``` --- ## New Features ### 1. ES Module Support jQuery 4.0 source has been migrated from AMD to ES modules, enabling better integration with modern build tools. #### Using with Modern Bundlers ```javascript // Rollup, Webpack, Vite, etc. import $ from 'jquery'; $(document).ready(() => { console.log('jQuery 4.0 with ES modules!'); }); ``` #### Dynamic Import ```javascript // Lazy load jQuery when needed async function initializeUI() { const { default: $ } = await import('jquery'); $('.dynamic-content').fadeIn(); } ``` ### 2. Trusted Types Support jQuery 4.0 adds support for Trusted Types, enhancing security in environments with strict Content Security Policies. ```javascript // jQuery now accepts TrustedHTML objects const policy = trustedTypes.createPolicy('myPolicy', { createHTML: (string) => DOMPurify.sanitize(string) }); const trustedContent = policy.createHTML('
Safe content
'); $('#container').html(trustedContent); ``` ### 3. Improved CSP Compatibility Async script requests now use ` ``` **Slim build excludes:** - Ajax module - Effects/animation module - Deferreds - Callbacks --- ## Migration Guide ### Using jQuery Migrate Plugin For gradual migration, use the jQuery Migrate plugin to identify deprecated features: ```html ``` The Migrate plugin will log warnings to the console for deprecated usage. ### Step-by-Step Migration #### Step 1: Update Utility Function Calls ```javascript // Before (jQuery 3.x) function processData(data) { if ($.isArray(data)) { return data.map(item => $.trim(item)); } return $.trim(data); } // After (jQuery 4.0) function processData(data) { if (Array.isArray(data)) { return data.map(item => item.trim()); } return data.trim(); } ``` #### Step 2: Update Type Checking ```javascript // Before (jQuery 3.x) function handleCallback(callback) { if ($.isFunction(callback)) { callback(); } } function getType(value) { return $.type(value); // "array", "date", "regexp", etc. } // After (jQuery 4.0) function handleCallback(callback) { if (typeof callback === 'function') { callback(); } } function getType(value) { if (Array.isArray(value)) return 'array'; if (value instanceof Date) return 'date'; if (value instanceof RegExp) return 'regexp'; return typeof value; } ``` #### Step 3: Handle Focus Event Order Changes ```javascript // If your code depends on specific event order, update accordingly $('#form-field').on('focusout', function() { // In jQuery 4.0, blur fires BEFORE focusout // Adjust validation logic if needed validateField(this); }); ``` #### Step 4: Update Array Method Usage ```javascript // Before (jQuery 3.x) const $items = $('.item'); $items.push(document.createElement('div')); // After (jQuery 4.0) - Option 1: Use native call const $items = $('.item'); [].push.call($items, document.createElement('div')); // After (jQuery 4.0) - Option 2: Use .add() const $items = $('.item').add(document.createElement('div')); ``` --- ## API Reference ### Core Functions #### `jQuery(selector [, context])` Select elements from the DOM. ```javascript // Select by ID const $header = $('#header'); // Select by class const $buttons = $('.btn'); // Select by tag const $paragraphs = $('p'); // Select with context const $items = $('.item', '#container'); // Create elements const $newDiv = $('New paragraph
').appendTo('#container'); ``` #### `.addBack([selector])` Add previous set to current set. ```javascript // Select all children and the parent $('#parent') .find('> *') .addBack() .addClass('highlighted'); // With filter $('ul') .find('li') .addBack('ul.main') .css('border', '1px solid'); ``` ### DOM Evaluation #### `jQuery.DOMEval(code, options)` Safely execute script code with nonce support (internal use, enhanced in 4.0). ```javascript // jQuery internally uses this for script execution // Preserves nonce attributes for CSP compliance // Handles type, src, nonce, and noModule attributes ``` --- ## Security Features ### Prototype Pollution Prevention jQuery 4.0 includes protection against prototype pollution attacks in `$.extend()`: ```javascript // These attempts are blocked $.extend(true, {}, JSON.parse('{"__proto__": {"polluted": true}}')); $.extend(true, {}, { constructor: { prototype: { polluted: true } } }); // Object.prototype remains unpolluted console.log({}.polluted); // undefined ``` ### XSS Mitigation The selector engine escapes special characters to prevent XSS: ```javascript // Safe selector escaping const userInput = 'div">'; const escaped = $.escapeSelector(userInput); // Safely escaped for use in selectors ``` ### CSP Compliance Script loading now complies with Content Security Policy: ```javascript // Scripts are loaded via