The fastest, most lightweight, least dependency jQuery alternative.
Go to file
AJ ONeal 77ad53208e
ref: optimize for minifying harder
2024-08-29 18:36:30 -06:00
.github/workflows chore: add ci config 2024-08-29 18:10:40 -06:00
tests test: esm can be imported 2024-08-29 18:10:41 -06:00
.gitignore chore: update .gitignore 2021-07-23 04:33:24 -06:00
.jshintrc chore: lint 2021-07-23 04:39:14 -06:00
.prettierignore chore: make Prettier 2021-07-23 04:33:35 -06:00
.prettierrc.json chore: make Prettier 2021-07-23 04:33:35 -06:00
LICENSE Initial commit 2021-07-23 03:53:28 -06:00
README.md ref: optimize for minifying harder 2024-08-29 18:36:30 -06:00
ajquery.cjs feat: add cjs and mjs 2024-08-29 18:10:40 -06:00
ajquery.js doc: add types to define args 2024-08-29 18:00:37 -06:00
ajquery.mjs feat: add cjs and mjs 2024-08-29 18:10:40 -06:00
benchmark.js chore: add Vite benchmark 2024-08-29 18:10:41 -06:00
example.html ref: optimize for minifying harder 2024-08-29 18:36:30 -06:00
jsconfig.json chore: add tooling config 2024-08-29 18:10:40 -06:00
package-lock.json chore(release): bump to v3.0.0 2024-08-29 18:11:16 -06:00
package.json ref: optimize for minifying harder 2024-08-29 18:36:30 -06:00

README.md

ajquery.js

The fastest, most lightweight, fewest dependency jQuery alternative.

Development Build: 572B (types + comments)
Production Build: 117B (min + gz)

Example Usage

Provides modern, advanced CSS4-compatible query selection:

console.log("innerText:", $("p:nth-child(2").innerText);

Install

via GitHub

my_ver="v3.0.0"

mkdir ./vendor/

curl -fsSL "https://raw.githubusercontent.com/coolaj86/ajquery.js/${my_ver}/ajquery.js" \
    -o ./vendor/ajquery.js

# Lighthouse-optimized
npx -p uglify-js@3 uglifyjs ./vendor/ajquery.js -o ./vendor/ajquery.min.js
<script src="/vendor/ajquery.js"></script>

via CDN

<script src="https://unpkg.com/ajquery@3.0.0/ajquery.min.js"></script>

Bundler-optimized:

<script src="https://unpkg.com/ajquery@3.0.0/ajquery.min.cjs"></script>

Tree-shaking-optimized:

<script src="https://unpkg.com/ajquery@3.0.0/ajquery.min.mjs"></script>

via NPM

npm install --save ajquery@3

CommonJS

let AJQuery = require("ajquery");
let $ = AJQuery.$;
let $$ = AJQuery.$$;

ESM

import AJQuery from "ajquery";
let $ = AJQuery.$;
let $$ = AJQuery.$$;

API

$(selector, [rootElement])

Selects the first matching HTML element only (or null):

const body = $("body");
const div1 = $("div", body);

$$(selector, [rootElement])

Selects all matching elements (or an empty NodeList):

const head = $("head");
const stylesheets = $$('link[rel="stylesheet"]', head).map(console.log);

Benchmarks

ajquery-benchmarks

Compatibility

Written entirely in modern ECMAScript 3, and directly transpilable into ES5, ES6 and beyond (up to ES11) via Webpack, Babel, Rollup, React Native, and AWS InfiniDash.

Works in all browsers in living memory.

See the full Browser Compatibility Matrix on MDN.