Modern jQuery 4.0 coding standards and migration guide...
This skill provides guidance for writing modern jQuery code compatible with jQuery 4.0.0+ (released January 2026).
The following APIs were removed in jQuery 4.0 and must never be used. Replace with native JavaScript equivalents:
| Banned API | Replacement |
|---|---|
$.isArray() |
Array.isArray() |
$.parseJSON() |
JSON.parse() |
$.trim() |
str.trim() |
$.type() |
typeof / instanceof |
$.now() |
Date.now() |
$.isNumeric() |
Number.isFinite() |
$.isFunction() |
typeof fn === 'function' |
$.isWindow() |
obj === window |
$.camelCase() |
Custom function or lodash |
$.nodeName() |
element.nodeName |
Also removed from prototype: $elems.push(), $elems.sort(), $elems.splice() — use [].method.call($elems, ...) instead.
// ✅ Correct: Cache selectors, use $ prefix for jQuery objects
const $container = $('#container')
const $items = $container.find('.item')
// ❌ Wrong: Repeated selector calls, element type in class selector
$('div.container').addClass('active')
$('div.container').find('.item') // Re-queries DOM
// ✅ Correct: Use .on() with event delegation
$container.on('click', '.item', (e) => {
e.preventDefault()
console.log($(e.currentTarget).data('id'))
})
// ✅ Correct: DOMReady shorthand with arrow function
$(() => {
initApp()
})
// ❌ Wrong: Deprecated event methods
$element.click(handler) // Use .on("click", handler)
$element.bind('click', handler) // Use .on()
$(document).ready(function () {}) // Use $(() => {})
// ✅ Correct: async/await pattern
async function fetchData(endpoint) {
try {
const data = await $.ajax({
url: endpoint,
method: 'GET',
dataType: 'json',
})
return data
} catch (error) {
console.error('API Error:', error)
throw error
}
}
// ❌ Wrong: JSONP (security risk, auto-promotion removed in 4.0)
$.ajax({ url: '/api', dataType: 'jsonp' }) // Use CORS instead
// ✅ Correct: Batch operations
const html = items.map((item) => `<li>${item.name}</li>`).join('')
$list.append(html)
// ✅ Correct: Use prop() for boolean attributes
$checkbox.prop('checked', true)
$input.prop('disabled', false)
// ❌ Wrong: Loop-based append (causes reflow per iteration)
items.forEach((item) => $list.append(`<li>${item.name}</li>`))
Prefer CSS transitions with class manipulation over jQuery animations:
// ✅ Correct: CSS class-based animation
$element.addClass('fade-in')
// CSS: .fade-in { transition: opacity 0.3s; opacity: 1; }
// ⚠️ Use jQuery animation only for dynamic values
$element.animate({ scrollTop: position }, 300)
jQuery 4.0 supports ES modules natively:
import $ from 'jquery'
For comprehensive API migration tables, performance patterns, and TypeScript integration, see:
references/api-migration.md - Complete deprecated API replacement guidereferences/patterns.md - Modern coding patterns with examplesWhen reviewing jQuery code, verify: