Description
Surreal is a tiny helper library that gives plain JavaScript a jQuery-style way to select and change elements, without a build step or dependencies. The library is about 320 lines. Its main functions are me(), which returns one element, and any(), which returns an array of elements, so you always know what you got. Both work with CSS selectors and can be chained, so you can add a class, set a style or attach an event in a single line. Functions work the same on one element or an array of them. The library adds Locality of Behavior: inside an inline script or event attribute, me() returns the element the script belongs to, so you do not need an id or class just to reach it. It also includes animations, timelines and tweens without other libraries, and its function names can be written in camelCase or snake_case. The README says it pairs well with htmx.…
Highlights
- me() for one element, any() for many
- Locality of Behavior with me() in inline code
- Chainable jQuery-style functions
- Animations and tweens without extra libraries
- About 320 lines, no dependencies
Ratings & Reviews
No ratings yet
Be the first to rate Surreal.
People also visit
Surreal FAQ
What is Surreal?
A tiny JavaScript library that offers a jQuery-style syntax for selecting and changing DOM elements, in plain JavaScript.
Does it need a build step?
No. The README says there is no build step and no dependencies, and it can be downloaded or loaded from a CDN.
What is the difference between me() and any()?
me() returns one element, or the first match, or null. any() always returns an array, which may be empty.
What is Locality of Behavior?
Inside an inline script, me() refers to the element the script belongs to, so you do not need a class or id.
Does it work with htmx?
The README says it pairs well with htmx.
What are the best Surreal alternatives?
Popular alternatives to Surreal include ///_hyperscript, SSGOI and Motion Core. See all Surreal alternatives









