Pattern Browser

164 patterns with 3936 translations across 24 languages. Search and filter to find the code you need.

Show patterns in:
Both _hyperscript LokaScript Unverified Example
Showing 164 of 164 results
Accessible Tabs ui-components

Tab navigation with ARIA attributes

on click set @aria-selected to "false" on .tab set @aria-selected to "true" on me
24 translations
Loading...
Accordion Toggle ui-components

Toggle accordion panel visibility

on click toggle .open on closest .accordion-item toggle @aria-expanded
24 translations
Loading...
Add Class class-manipulation

Add a CSS class to the current element when clicked

on click add .highlight to me
24 translations
Loading...
Add Class To Other class-manipulation

Add a CSS class to another element

on click add .selected to #item
24 translations
Loading...
Append Content dom-manipulation

Append content to an element

on click append "<li>Item</li>" to #list
24 translations
Loading...
Async Block advanced

Execute commands asynchronously

on click async fetch /api/data then put it into me
24 translations
Loading...
Beep Debug Expression debugging

Use beep! to debug-print an expression result without altering control flow

on click set $x to beep! my value
24 translations
Loading...
Bind To Explicit Property both reactivity

Use possessive syntax to bind to a named property explicitly (preferred — reads in any language)

bind $color to #picker's value
24 translations
Loading...
Bind Variable To Display-Only Element both reactivity

For non-form properties, only var→DOM fires; user mutations of the property are not observed

bind $message to #status's textContent
24 translations
Loading...
Bind Variable To Form Element both reactivity

Two-way bind a global variable to an input; property auto-detected (value/checked/etc.)

bind $greeting to #name-input
24 translations
Loading...
Blur Element focus

Remove focus from element

on keydown[key=="Escape"] blur me
24 translations
Loading...
Breakpoint In Handler debugging

Pause execution at a breakpoint and inspect state in the HDB debugger

on click breakpoint then set $x to 42
24 translations
Loading...
Build HTML List From Items templates

Build an HTML list by iterating items and concatenating template literals

on click set $html to "" then for item in $items set $html to $html + `<li>${item.name}</li>` end then set #list.innerHTML to $html
24 translations
Loading...
Call Function advanced

Call a JavaScript function

on click call myFunction()
24 translations
Loading...
Chained Property Access (Possessive Dot) lokascript hyperfixi-extensions

Chained property access using possessive dot notation (HyperFixi extension)

on click set my.parentElement.style.display to "none"
24 translations
Loading...
Character Counter forms

Show character count as user types

on input set #count.innerText to my value.length
24 translations
Loading...
Clear Input forms

Clear the previous input field

on click set previous <input/>.value to ""
24 translations
Loading...
Click Elsewhere events

Handle clicks outside element

on click from elsewhere remove .open from me
24 translations
Loading...
Close Dropdown On Outside Click ui-components

Close dropdown when clicking outside

on click from elsewhere remove .open from .dropdown-menu
24 translations
Loading...
Close Modal Button ui-components

Close modal from button inside

on click hide closest .modal remove .modal-open from body
24 translations
Loading...
Close Modal On Backdrop Click ui-components

Close modal by clicking outside

on click if target matches .modal-backdrop hide .modal-backdrop end
24 translations
Loading...
Close Modal On Escape ui-components

Close modal when pressing Escape key

on keydown[key=="Escape"] from window hide .modal remove .modal-open from body
24 translations
Loading...
Closest Ancestor navigation

Toggle class on closest matching ancestor

on click toggle .expanded on closest .card
24 translations
Loading...
Component: Attrs Into ^var both components

Component reading attrs.data (JSON-encoded) into ^user via init script

<script type="text/hyperscript-template" component="user-card" _="set ^user to attrs.data as JSON"> <h3>${^user.name}</h3> #if ^user.admin <span class="badge">admin</span> #end </script>
24 translations
Loading...
Component: Click Counter both components

Component with isolated DOM-scoped state (^count) that re-renders on change

<script type="text/hyperscript-template" component="click-counter" _="set ^count to 0"> <button _="on click increment ^count">+</button> <span>Clicks: ${^count}</span> </script>
24 translations
Loading...
Component: Conditional Rendering both components

Component using ^var state and the #if directive for conditional rendering

<script type="text/hyperscript-template" component="user-card" _="set ^user to {name: 'Demo', admin: true}"> <h3>${^user.name}</h3> #if ^user.admin <span class="badge">admin</span> #end </script>
24 translations
Loading...
Component: Default And Named Slots both components

Component with default and named slots for content projection

<script type="text/hyperscript-template" component="my-layout"> <header><slot name="title"/></header> <main><slot/></main> <footer><slot name="footer"/></footer> </script>
24 translations
Loading...
Component: Hello World both components

Define a custom element via a hyperscript-template script tag

<script type="text/hyperscript-template" component="hello-world"> <span>Hello World</span> </script>
24 translations
Loading...
Computed Value data

Calculate and display computed value

on input from .quantity set #total.innerText to (the value of #price as Number) * (my value as Number)
24 translations
Loading...
Copy To Clipboard clipboard

Copy text to clipboard with feedback

on click call navigator.clipboard.writeText(#code.innerText) put "Copied!" into me wait 2s put "Copy" into me
24 translations
Loading...
Decrement Counter counters

Decrement a numeric counter element

on click decrement #counter
24 translations
Loading...
Default Value data

Set default value if not present

on load default my @data-count to "0"
24 translations
Loading...
Disable Form On Submit forms

Disable submit button while processing

on submit add @disabled to <button/> in me put "Submitting..." into <button/> in me
24 translations
Loading...
Document Ready window-events

Initialize app when element loads

on load call initializeApp()
24 translations
Loading...
Draggable Behavior behavior

Makes element draggable with pointer events. Use: install Draggable(dragHandle: ".titlebar")

behavior Draggable(dragHandle) init if no dragHandle set dragHandle to me end on pointerdown(clientX, clientY) from dragHandle halt the event trigger draggable:start measure x set startX to it measure y set startY to it set xoff to clientX - startX set yoff to clientY - startY repeat until event pointerup from document wait for pointermove(clientX, clientY) or pointerup(clientX, clientY) from document add { left: ${clientX - xoff}px; top: ${clientY - yoff}px; } trigger draggable:move end trigger draggable:end end end
24 translations
Loading...
Dropdown Toggle ui-components

Toggle dropdown menu visibility

on click toggle .open on next .dropdown-menu halt
24 translations
Loading...
Event Debounce events

Debounce input for search

on input debounced at 300ms fetch /api/search?q=${my value} as json then put it into #results
24 translations
Loading...
Event Once events

Handle event only once

on click once add .initialized to me call setup()
24 translations
Loading...
Event Throttle events

Throttle scroll handler

on scroll throttled at 100ms call updateScrollPosition()
24 translations
Loading...
Exclusive Accordion ui-components

Accordion where only one panel is open

on click remove .open from .accordion-item add .open to closest .accordion-item
24 translations
Loading...
Fade Out And Remove animation

Fade element out then remove from DOM

on click transition opacity to 0 over 300ms then remove me
24 translations
Loading...
Fetch Data async

Fetch data from an API and display it

on click fetch /api/data then put it into #result
24 translations
Loading...
Fetch JSON async

Fetch JSON data and use a property

on click fetch /api/user as json then set #name.innerText to it.name
24 translations
Loading...
Fetch With Auth Header async

Fetch with custom headers and parse the response as JSON

on click fetch /api/me with headers:{Authorization:`Bearer ${$token}`} as JSON then put it.name into me
24 translations
Loading...
Fetch With Error Handling async

Handle API errors by checking response body

on click fetch /api/data as json then if it.error put it.error into #error else put it.data into #result end
24 translations
Loading...
Fetch With Loading State async

Show loading indicator during fetch

on click add .loading to me fetch /api/data then remove .loading from me put it into #result
24 translations
Loading...
Fetch With Method async

Submit form data via POST

on submit fetch /api/form with method:"POST" body:form
24 translations
Loading...
Fetch Without Throwing async

Fetch without throwing on errors; check the result before using it

on click fetch /api/users as JSON do not throw then if it set $users to it end
24 translations
Loading...
First In Collection navigation

Focus first input in parent form

on click focus first <input/> in closest <form/>
24 translations
Loading...
Focus Element focus

Focus an input element

on click focus #input
24 translations
Loading...
Focus Trap accessibility

Trap focus within modal

on keydown[key=="Tab"] from .modal if target matches last <button/> in .modal focus first <button/> in .modal halt end
24 translations
Loading...
Get Attribute (Possessive Dot) lokascript hyperfixi-extensions

Call getAttribute using possessive dot notation (HyperFixi extension)

on click put my.getAttribute("data-id") into #output
24 translations
Loading...
Get Input Value (Possessive Dot) lokascript hyperfixi-extensions

Mirror input value using possessive dot notation (HyperFixi extension)

on input put my.value into #preview
24 translations
Loading...
Get Value data

Get a value and use it

on click get #input.value then log it
24 translations
Loading...
Go Back navigation

Navigate back in history

on click go back
24 translations
Loading...
Go To URL navigation

Navigate to a URL

on click go to url "/page"
24 translations
Loading...
Halt Event control-flow

Stop event propagation

on click halt the event then toggle .active
24 translations
Loading...
Hide Element visibility

Hide an element

on click hide #modal
24 translations
Loading...
Hide With Transition visibility

Hide element with opacity transition

on click hide me with *opacity
24 translations
Loading...
If Condition control-flow

Conditional execution based on state

on click if I match .active then remove .active else add .active end
24 translations
Loading...
If Element Exists control-flow

Check if element exists before action

on click if #modal exists show #modal else make a <div#modal/> put it into body end
24 translations
Loading...
If Matches Selector control-flow

Check if element matches selector

on click if I match .disabled halt else toggle .active end
24 translations
Loading...
If Value Empty control-flow

Validate empty input

on blur if my value is empty add .error to me put "Required" into next .error-message end
24 translations
Loading...
Increment By Amount counters

Increment counter by specific amount

on click increment #score by 10
24 translations
Loading...
Increment Counter counters

Increment a numeric counter element

on click increment #counter
24 translations
Loading...
Increment Inherited DOM-Scoped Variable both reactivity

Walks up the parent chain to find ^count and writes the nearest defining ancestor

on click increment ^count
24 translations
Loading...
Inline JavaScript advanced

Execute inline JavaScript

on click js console.log("from js") end
24 translations
Loading...
Input Mirror forms

Mirror input value to another element

on input put my value into #preview
24 translations
Loading...
Input Validation forms

Validate input on blur

on blur if my value is empty add .error to me else remove .error from me end
24 translations
Loading...
Install Behavior behaviors

Install a reusable behavior on an element. Replace "Draggable" with any defined behavior name (e.g., Sortable, Closeable).

install Draggable
24 translations
Loading...
Intercept: Cache Strategies both service-workers

Service worker DSL with precaching, per-route strategies, and offline fallback

intercept / precache /, /style.css, /app.js as "v1" on /api/* use network-first on *.css, *.js use cache-first on * use stale-while-revalidate offline fallback /offline.html end
24 translations
Loading...
Its Value (Possessive Dot) lokascript hyperfixi-extensions

Access result property using its.property syntax (HyperFixi extension)

on click fetch /api/data then put its.name into #result
24 translations
Loading...
Key Combination events

Handle Shift+Enter key combo

on keydown[key=="Enter"] if event.shiftKey call submitAndContinue() end
24 translations
Loading...
Key Filter With `is` events

Filter keyboard events using the modern `is` comparison syntax

on keyup[key is 'Escape'] clear me
24 translations
Loading...
Last In Collection navigation

Scroll to last message in chat

on click scroll to last <.message/> in #chat
24 translations
Loading...
Live Block With Multiple Dependencies both reactivity

Body re-runs only when one of its tracked reads ($price or $quantity) changes

live put `${$price * $quantity}` into #total end
24 translations
Loading...
Live Derived Value both reactivity

Reactively update content whenever a tracked dependency changes

live put `Count: ${$count}` into me end
24 translations
Loading...
Log Element debugging

Log the current element to console

on click log me
24 translations
Loading...
Log Value debugging

Log a message to the console

on click log "Button clicked!"
24 translations
Loading...
Make Element dom-manipulation

Create a new element dynamically

on click make a <div.card/> then put it into #container
24 translations
Loading...
Make Toast Element templates

Create a new element, populate its content, and append it to the document

on click make a <div.toast/> then put 'Saved!' into it then put it at end of body
24 translations
Loading...
Method Call (Possessive Dot) lokascript hyperfixi-extensions

Call method on property using possessive dot notation (HyperFixi extension)

on input put my.value.toUpperCase() into #preview
24 translations
Loading...
Morph Fetched HTML morphing

Fetch HTML and morph the DOM in place, preserving focus and form state

on click fetch /api/items then morph #list to it
24 translations
Loading...
Morph Form Without Losing Focus morphing

Morph a form after submit so users keep focus, scroll position, and unsaved values

on submit fetch /api/save then morph closest <form/> to it
24 translations
Loading...
Morph Rendered Template morphing

Render a template then morph it into the target element

on click render #row with row: $data then morph #target to it
24 translations
Loading...
Multiple Event Handlers events

Handle multiple events with one handler

on click or keypress[key=="Enter"] toggle .active
24 translations
Loading...
Next Element navigation

Select and modify next sibling element

on click add .highlight to next <li/>
24 translations
Loading...
Open Modal ui-components

Open modal and prevent body scroll

on click show #modal add .modal-open to body
24 translations
Loading...
Optional Chaining (Possessive) lokascript hyperfixi-extensions

Safe property access using optional chaining (HyperFixi extension)

on click log my?.dataset?.customValue
24 translations
Loading...
POST With Method And Body async

POST to an endpoint by passing method and body as fetch options

on click fetch /api/users with method:"POST", body:"name=Joe"
24 translations
Loading...
Pick Text Range dom-manipulation

Select a text range within an input or contenteditable using the pick command

on click pick characters 0 to 5 of #note
24 translations
Loading...
Prevent Form Submit forms

Prevent form submission and validate

on submit halt the event call validateForm() if result is false log "Invalid form" end
24 translations
Loading...
Previous Element navigation

Select and modify previous sibling element

on click remove .highlight from previous <li/>
24 translations
Loading...
Put After dom-manipulation

Insert content after the current element

on click put "<p>New</p>" after me
24 translations
Loading...
Put Before dom-manipulation

Insert content before the current element

on click put "<p>New</p>" before me
24 translations
Loading...
Put Content dom-manipulation

Replace the content of the current element

on click put "Done!" into me
24 translations
Loading...
Reactive Array Mutation both reactivity

Mutate a reactive array; live blocks reading it re-render automatically

on click call $items.push(`item ${$items.length + 1}`)
24 translations
Loading...
Read DOM-Scoped Variable From Another Element both reactivity

Read a ^name variable scoped to a specific element instead of walking up from `me`

on click put ^count on #host into me
24 translations
Loading...
Receive Custom Event events

Receive a custom event and update the receiving element's content

on hello put 'Got it!' into me
24 translations
Loading...
Removable Behavior behavior

Removes element on click with optional confirmation and fade effect. Use: install Removable(confirmRemoval: true, effect: "fade")

behavior Removable(triggerEl, confirmRemoval, effect) init if triggerEl is undefined set triggerEl to me end end on click from triggerEl if confirmRemoval js(me) if (!window.confirm("Are you sure?")) return "cancel"; end if it is "cancel" halt end end trigger removable:before if effect is "fade" transition opacity to 0 over 300ms end trigger removable:removed remove me end end
24 translations
Loading...
Remove Class class-manipulation

Remove a CSS class from the current element when clicked

on click remove .highlight from me
24 translations
Loading...
Remove Class From All class-manipulation

Remove a CSS class from all matching elements

on click remove .active from .items
24 translations
Loading...
Remove Element dom-manipulation

Remove the current element from the DOM

on click remove me
24 translations
Loading...
Render Template With Data templates

Render a named template element with data, then insert the HTML into the DOM

on click render #user-list with users: $data then put it into #container
24 translations
Loading...
Repeat For Each loops

Iterate over a collection

on click repeat for item in .items add .processed to item
24 translations
Loading...
Repeat Forever loops

Infinite animation loop

on load repeat forever toggle .pulse wait 1s end
24 translations
Loading...
Repeat Times loops

Repeat an action multiple times

on click repeat 3 times add "<p>Line</p>" to me
24 translations
Loading...
Repeat Until Event loops

Repeat action while button is held

on mousedown repeat until event mouseup increment #counter wait 100ms end
24 translations
Loading...
Repeat While Condition loops

Repeat while condition is true

on click repeat while #counter.innerText < 10 increment #counter wait 200ms end
24 translations
Loading...
Resizable Behavior behavior

Makes elements resizable by dragging. Use: install Resizable(minWidth: 100, minHeight: 100)

behavior Resizable(minWidth, minHeight, maxWidth, maxHeight) on pointerdown(clientX, clientY) from me halt the event trigger resizable:start measure width set startWidth to it measure height set startHeight to it set startX to clientX set startY to clientY repeat until event pointerup from document wait for pointermove(clientX, clientY) from document set newWidth to startWidth + clientX - startX set newHeight to startHeight + clientY - startY if newWidth < minWidth then set newWidth to minWidth end if newWidth > maxWidth then set newWidth to maxWidth end if newHeight < minHeight then set newHeight to minHeight end if newHeight > maxHeight then set newHeight to maxHeight end set my style.width to newWidth + "px" set my style.height to newHeight + "px" trigger resizable:resize end trigger resizable:end end end
24 translations
Loading...
Resize Handler window-events

Handle window resize with debounce

on resize from window debounced at 200ms call adjustLayout()
24 translations
Loading...
SSE With Multiple Event Names lokascript realtime

One SSE connection routing several named server events into the same target

<div sse-connect="/feed" sse-swap="post, like, comment" hx-target="#timeline" hx-swap="afterbegin"></div>
24 translations
Loading...
Screen Reader Announcement accessibility

Announce message to screen readers

on success put event.detail.message into #sr-announce set @role to "alert" on #sr-announce
24 translations
Loading...
Scroll Handler window-events

Add sticky class on scroll

on scroll from window if window.scrollY > 100 add .sticky to #header else remove .sticky from #header end
24 translations
Loading...
Send Custom Event events

Dispatch a custom event to another element

on click send refresh to #widget
24 translations
Loading...
Send Custom Event To Form events

Dispatch a custom event named hello to all form elements

on click send hello to <form/>
24 translations
Loading...
Send Event With Detail events

Send an event with data payload

on click send update(value: 42) to #target
24 translations
Loading...
Send To Named Socket realtime

Send a message to a previously-declared WebSocket from a click handler

on click send "hello" to ChatSocket
24 translations
Loading...
Server-Sent Events Source both realtime

Subscribe to a server-sent events endpoint and append messages to the DOM

eventsource ChatStream from /events on message put it into #messages end
24 translations
Loading...
Server-Sent Events Stream Into Target lokascript realtime

Open an EventSource and route named events through hx-target/hx-swap

<div sse-connect="/events" sse-swap="tick" hx-target="#feed" hx-swap="afterbegin"></div>
24 translations
Loading...
Set Attribute dom-manipulation

Set an attribute on the current element

on click set @disabled to true
24 translations
Loading...
Set CSS Variable css-styles

Set a CSS custom property

on click set the *--primary-color of #theme to "#ff6600"
24 translations
Loading...
Set DOM-Scoped Variable On Parent both reactivity

Declare a ^name variable on this element; descendants can read and write it

on load set ^count to 0
24 translations
Loading...
Set Opacity css-styles

Set CSS opacity using possessive syntax

on click set my *opacity to 0.5
24 translations
Loading...
Set Style dom-manipulation

Set a CSS style property

on click set my *background to "red"
24 translations
Loading...
Set Text (Possessive Dot) lokascript hyperfixi-extensions

Set text content using possessive dot notation (HyperFixi extension)

on click set my.textContent to "Done!"
24 translations
Loading...
Set Text Content dom-manipulation

Set the text content of an element by ID

on click set #output.innerText to "Hello World"
24 translations
Loading...
Set Transform css-styles

Set CSS transform property

on click set my *transform to "rotate(45deg)"
24 translations
Loading...
Set innerHTML (Possessive Dot) lokascript hyperfixi-extensions

Set innerHTML using possessive dot notation (HyperFixi extension)

on click set my.innerHTML to "<strong>Updated!</strong>"
24 translations
Loading...
Settle Animations animation

Wait for CSS animations to complete

on click add .animate then settle then remove .animate
24 translations
Loading...
Show Element visibility

Show a hidden element

on click show #modal
24 translations
Loading...
Show With Transition visibility

Show element with opacity transition

on click show #modal with *opacity
24 translations
Loading...
Slide Toggle animation

Slide panel open/closed

on click toggle .collapsed on next .panel transition *max-height over 300ms
24 translations
Loading...
Sortable Behavior behavior

Makes child elements reorderable via drag-and-drop. Use: install Sortable(handle: ".drag-handle")

behavior Sortable(dragClass) init if dragClass is undefined set dragClass to "sorting" end end on pointerdown(clientY) from me set item to the closest <li/> to the target if item is null exit end halt the event add .{dragClass} to item trigger sortable:start on me repeat until event pointerup from document wait for pointermove(clientY) from document trigger sortable:move on me end remove .{dragClass} from item trigger sortable:end on me end end
24 translations
Loading...
Stagger Animation animation

Staggered entrance animation

on load repeat for item in .item with index add .visible to item wait 100ms end
24 translations
Loading...
Submit Form As FormData async

Serialize the closest form as FormData and POST it

on submit fetch /api/submit with method:"POST", body:(closest <form/> as FormData)
24 translations
Loading...
Swap Content dom-manipulation

Swap two elements in the DOM

on click swap #a with #b
24 translations
Loading...
Tab Navigation ui-components

Basic tab switching with active state

on click remove .active from .tab add .active to me
24 translations
Loading...
Tab With Content Panel ui-components

Tab that shows associated content panel

on click remove .active from .tab add .active to me hide .tab-panel show the next <div.tab-panel/>
24 translations
Loading...
Take Class From Siblings (Tabs) dom-manipulation

Take a class from sibling elements and apply it to the current one (canonical tabs idiom)

on click take .active from .tab-button for me
24 translations
Loading...
Tell Another Element events

Run a sequence of commands on another element using tell

on click tell #panel add .open then wait 200ms then add .visible
24 translations
Loading...
Tell Command behaviors

Tell another element to execute a command

on click tell #modal to show
24 translations
Loading...
Template Literal Interpolation templates

Use backtick template literals to interpolate values into HTML

on click set my innerHTML to `<li>${$item.name}</li>`
24 translations
Loading...
Toggle ARIA Expanded accessibility

Toggle ARIA expanded state

on click toggle @aria-expanded on me toggle .open on next .panel
24 translations
Loading...
Toggle Class class-manipulation

Toggle a CSS class on the current element when clicked

on click toggle .active
24 translations
Loading...
Toggle Class On Other Element class-manipulation

Toggle a CSS class on another element

on click toggle .open on #menu
24 translations
Loading...
Toggle Visibility visibility

Toggle the hidden attribute on an element

on click toggle @hidden on #panel
24 translations
Loading...
Transition Background Color css-styles

Animate background color change

on click transition *background-color to "blue" over 500ms
24 translations
Loading...
Transition Opacity animation

Animate opacity then remove the element

on click transition opacity to 0 over 500ms then remove me
24 translations
Loading...
Transition Transform animation

Animate transform property

on click transition transform to "scale(1.2)" over 300ms
24 translations
Loading...
Trigger Event events

Trigger a custom event when the element loads

on load trigger init
24 translations
Loading...
Two-Way Bind Two Inputs both reactivity

Share a global between two inputs by binding both to it; edits in either propagate to the other

bind $name to #input-a then bind $name to #input-b
24 translations
Loading...
Two-Way Binding data

Update display as input changes

on input from #firstName set #greeting.innerText to "Hello, " + my value
24 translations
Loading...
Unless Condition control-flow

Execute unless condition is true

on click unless I match .disabled toggle .selected
24 translations
Loading...
Wait For Event timing

Wait for a DOM event to fire

on click wait for transitionend
24 translations
Loading...
Wait Then Execute timing

Wait for a duration before executing a command

on click wait 2s then remove me
24 translations
Loading...
Web Worker Definition both realtime

Define a Web Worker in hyperscript and call its methods like a normal object

worker Calculator def add(a, b) return a + b end end
24 translations
Loading...
WebSocket Listener both realtime

Open a WebSocket and route incoming messages into the DOM

socket ChatSocket ws://localhost:8080 on message put it into #chat end
24 translations
Loading...
WebSocket With Form Send lokascript realtime

Open a WebSocket on an element; descendant forms serialize fields to JSON and ws-send on submit

<div ws-connect="wss://example/api"> <form ws-send> <input name="msg" /> <button type="submit">Send</button> </form> </div>
24 translations
Loading...
When Any Of Several Values Change both reactivity

Watch multiple expressions; body fires when any one of them changes

when $firstName or $lastName changes put `${$firstName} ${$lastName}` into #full-name end
24 translations
Loading...
When Computed Value Changes both reactivity

React to changes in a computed expression; `it` is the new value

when (#price's value * #qty's value) changes put `$${it}` into me end
24 translations
Loading...
Window Keydown Handler window-events

Handle Ctrl+S globally

on keydown[key=="s"] from window if event.ctrlKey halt call saveDocument() end
24 translations
Loading...
hx-live Plus Hyperscript Mutator lokascript reactivity

Pair a hyperscript handler that writes a global with an hx-live element that re-renders on writes

<button _="on click set $count to ($count or 0) + 1">+1</button> <div hx-live="put $count into me"></div>
24 translations
Loading...
hx-live Reactive Attribute lokascript reactivity

htmx v4 attribute that re-runs the hyperscript body whenever a tracked read changes

<div hx-live="put $count into me"></div>
24 translations
Loading...