Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use the htmx JavaScript API for imperative integration in server-rendered apps. Use when calling htmx.ajax, htmx.process, htmx.trigger, htmx.on, htmx.off, htmx.onLoad, htmx.find, htmx.findAll, htmx.closest, htmx.addClass, htmx.removeClass, htmx.toggleClass, htmx.takeClass, configuring htmx.config, logging htmx events, or integrating non-htmx JavaScript with swapped content.
.claude/skills/hashgraph-online-htmx-js-api/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-16 | ✗→✓ | ▲ Improved | -53% | 0% |
| case-19 | ✗→✓ | ▲ Improved | -10% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 154% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 15% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 37% | 0% |
Use this skill when declarative attributes are not enough. Prefer attributes first; reach for the JavaScript API to integrate with third-party widgets, dynamically injected markup, instrumentation, or programmatic request flows.
Use htmx attributes when the behavior is visible in the HTML and tied to one element. Use the JS API when:
Set global config once before relying on htmx behavior. Common examples:
htmx-security.Keep config close to where htmx is loaded so there is one source of truth.
Use htmx DOM helpers for concise integration code:
| Need | Methods | | --- | --- | | Find one element | htmx.find, htmx.closest | | Find many elements | htmx.findAll | | Remove an element | htmx.remove | | Add a class | htmx.addClass | | Remove a class | htmx.removeClass | | Toggle a class | htmx.toggleClass | | Make one element selected | htmx.takeClass |
Do not use helper calls to hide complex UI state that belongs in a component or server response.
htmx.on for delegated or global listeners.htmx.off when unregistering listeners from code that can mount/unmount.htmx.trigger to bridge plain JavaScript events into htmx behavior.htmx.onLoad for behavior that must run on newly loaded htmx content.Example:
jshtmx.on("saved", function (event) { console.info("Saved", event.detail); }); htmx.trigger("#results", "filters:changed");
Use htmx.ajax when code needs to initiate an htmx request while preserving htmx swap semantics.
jshtmx.ajax("GET", "/notifications", { target: "#notifications", swap: "innerHTML" });
Before using htmx.ajax, ask whether a real link, button, or form with htmx attributes would be clearer and more accessible.
Use htmx.process(element) after non-htmx code injects markup that contains htmx attributes.
jsconst panel = document.querySelector("#panel"); panel.innerHTML = htmlFromTrustedSource; htmx.process(panel);
Only process trusted markup. If markup includes user content, review sanitization with htmx-security before insertion.
htmx.logAll() temporarily while diagnosing event/request behavior.htmx.logNone() after debugging.htmx.logger for structured local diagnostics.Use extension APIs only when a documented htmx extension or project-specific integration requires it. For WebSocket and SSE work, prefer htmx-realtime for transport design before writing extension code.
fetch() plus innerHTML.htmx.config from feature code after the app has started.Other measured skills in the registry, with their headline benchmark lift.