You-Dont-Need-jQuery README

The project's README from github.com/camsong/You-Dont-Need-jQuery. As one markdown file: README.md.

You (Might) Don't Need jQuery

Frontend environments evolve rapidly nowadays and modern browsers have already implemented a great deal of DOM/BOM APIs which are good enough for production use. We don't have to learn jQuery from scratch for DOM manipulation or event handling. In the meantime, thanks to the spread of frontend libraries such as React, Angular and Vue, manipulating the DOM directly becomes anti-pattern, so that jQuery usage has never been less important. This project summarizes most of the alternatives in native JavaScript implementation to jQuery methods.

Snippets target current evergreen browsers (Chrome, Edge, Firefox, Safari). Internet Explorer is no longer supported by Microsoft, so IE-specific fallbacks have been removed. If you still need them, see the last IE-compatible version.

ℹ️ Notice:

  1. jQuery is still a great library and has many valid use cases. Don’t migrate away if you don’t want to!
  2. The alternatives are not completely equivalent in all scenarios, and it is recommended that you test it before using it.

Table of Contents

  1. Translations
  2. Query Selector
  3. CSS & Style
  4. DOM Manipulation
  5. Ajax
  6. Events
  7. Utilities
  8. Promises
  9. Animation
  10. Alternatives
  11. Browser Support

Translations

Query Selector

In place of common selectors like class, id or attribute we can use document.querySelector or document.querySelectorAll for substitution. The differences lie in:

Notice: document.getElementById, document.getElementsByClassName and document.getElementsByTagName are slightly faster than querySelector*, but getElementsBy* return a live HTMLCollection that changes as the DOM changes. Prefer querySelector* unless you have measured a bottleneck.

⬆ back to top

CSS & Style

⬆ back to top

DOM Manipulation

⬆ back to top

Ajax

Fetch API is the standard replacement for XMLHttpRequest and works in all modern browsers. Unlike $.ajax, fetch does not reject on HTTP error status such as 404 or 500; check response.ok yourself. For JSONP, try fetch-jsonp.

⬆ back to top

Events

⬆ back to top

Utilities

Most of jQuery utilities are also found in the native API. Other advanced functions could be chosen from better utilities libraries, focusing on consistency and performance. Lodash and es-toolkit are recommended replacements.

⬆ back to top

Promises

A promise represents the eventual result of an asynchronous operation. jQuery has its own way to handle promises. Native JavaScript implements a thin and minimal API to handle promises according to the Promises/A+ specification, and async/await makes them read like synchronous code.

⬆ back to top

Animation

The Web Animations API (el.animate()) is the closest native match to jQuery effects: it takes a duration in milliseconds, runs off the main thread where possible, and returns an Animation whose finished promise resolves when it ends.

Alternatives

Browser Support

Chrome Edge Firefox Safari Opera
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔

A few snippets use newer APIs: Promise.withResolvers() (2024), el.replaceChildren() (2020) and AbortSignal.timeout() (2022). Check Baseline if you support older browsers.

License

MIT

You-Dont-Need-jQuery (camsong/You-Dont-Need-jQuery)

Searching Database…

What is this?A reference guide that shows the plain JavaScript (native DOM/BOM) equivalent for common jQuery methods like querying, styling, DOM manipulation, ajax, events, utilities, promises and animation.
Is this a library I install, or just a reference doc?It is not a library to install — it is a documentation/code-snippet collection organized by topic (selectors, CSS, DOM, Ajax, Events, Utilities, Promises, Animation) that you copy patterns from.
How do I use this?Browse the table of contents for the jQuery feature you need (e.g. query selector, ajax, events) and copy the equivalent vanilla JS snippet shown next to it.
Do I need jQuery or any library to use these snippets?No, that is the whole point — snippets use only native browser APIs like querySelector, fetch, and the Web Animations API.
Will every snippet behave exactly like the jQuery method it replaces?No, the project itself warns the alternatives aren't fully equivalent in every scenario, so you should test before using them in production.
Does this still support Internet Explorer?No, IE-specific fallbacks were removed since Microsoft dropped support; an older IE-compatible version of the README is linked if needed.
Should I stop using jQuery entirely after reading this?No — the README explicitly says jQuery is still a great library with valid use cases, so it's fine to keep using it if you want.
Does it cover Ajax replacements?Yes, it recommends the Fetch API as the standard replacement for XMLHttpRequest, noting that unlike $.ajax, fetch does not reject on HTTP error statuses like 404 or 500.
What about jQuery's utility functions like extend or each?Most are mapped to native equivalents (Object.assign/spread, Array methods), and for more advanced utilities the guide recommends Lodash or es-toolkit instead.
How does it handle animations without jQuery?It recommends the Web Animations API (el.animate()) as the closest native match to jQuery effects, running off the main thread with a finished promise.
Creator
camsong
Size
0.9 MB
Stars
20.1K
Age
10y
Commits · 90 Days