Migrate

Migrate from jQuery

For most pages: swap one script tag, run your test pass, and fix the handful of differences below. Then adopt the new modules at your own pace.

The checklist

  1. Replace the jQuery script tag with `jskjs.min.js — see CDN. jsKjs also defines window.jQuery if nothing else has.
  2. Search your code for the APIs in “Removed and replaced” and for jQuery-only selectors (:visible, :first, :eq).
  3. Check AJAX error handlers: xhr.status → err.status.
  4. Run your tests or click through. Most pages need no further changes.
  5. Optional: replace hand-wired AJAX with kj-* attributes, state juggling with kj-data, and .animate() with $.to().

Behaviour that differs

DifferenceWhat to do
$.ajax() returns a native Promise (not jqXHR).done/.fail/.always and callbacks still work. xhr.status becomes err.status; xhr.responseText becomes err.data.
Handlers receive the native EventUse e.key, e.target, e.detail. e.originalEvent does not exist (you already have it).
.trigger(type, payload) takes one payloadPass an object instead of an array of extra parameters.
.val() on a checkbox returns true/falseUse .attr("value") if you need the value attribute.
Collections are real ArraysNative .map() (callback (el, i)) returns a plain array. jQuery's .map((i, el) => …) → use $.map() or swap the parameters.
Selectors are pure CSSReplace :visible, :first, :eq(n), :even with methods or CSS (:nth-child).
Browser supportEvergreen only: no IE11, no pre-2021 Safari/Firefox.

Removed and replaced

jQueryUse instead
.stop() .finish() .delay() .queue()await, $.timeline(), setTimeout
$.Deferred() $.when()new Promise(), Promise.all()
.bind() .live() .delegate().on() with a selector
$.ajaxSetup()a small wrapper around $.ajax
.nextAll() .prevAll() .parentsUntil()loops with .next() / .parent(), or native APIs
.wrapAll() .wrapInner() .unwrap()native DOM (before/append)
.innerWidth() .outerWidth()getBoundingClientRect() / clientWidth
$.grep() $.inArray()Array.prototype.filter / includes

Let an agent do it

Prompt
Replace jQuery with jsKjs in this project. Keep behaviour identical. Flag every use of APIs jsKjs does not include (.stop, .delay, $.Deferred, .nextAll, $.ajaxSetup, JSONP) and propose replacements. Note: .val() on checkboxes returns a boolean in jsKjs.

Full line-by-line comparison with jQuery 4 →