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
- Replace the jQuery script tag with `jskjs.min.js — see CDN. jsKjs also defines
window.jQueryif nothing else has. - Search your code for the APIs in “Removed and replaced” and for jQuery-only selectors (
:visible,:first,:eq). - Check AJAX error handlers:
xhr.status→err.status. - Run your tests or click through. Most pages need no further changes.
- Optional: replace hand-wired AJAX with
kj-*attributes, state juggling withkj-data, and.animate()with$.to().
Behaviour that differs
| Difference | What 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 Event | Use e.key, e.target, e.detail. e.originalEvent does not exist (you already have it). |
.trigger(type, payload) takes one payload | Pass an object instead of an array of extra parameters. |
.val() on a checkbox returns true/false | Use .attr("value") if you need the value attribute. |
| Collections are real Arrays | Native .map() (callback (el, i)) returns a plain array. jQuery's .map((i, el) => …) → use $.map() or swap the parameters. |
| Selectors are pure CSS | Replace :visible, :first, :eq(n), :even with methods or CSS (:nth-child). |
| Browser support | Evergreen only: no IE11, no pre-2021 Safari/Firefox. |
Removed and replaced
| jQuery | Use 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.