up.fragment
The JavaScript API to render, look up and destroy page fragments. Every link, form, overlay or poll that Unpoly handles ends in up.render(), and your own code can call it with the same options.
up.render() replaces elements on the current page with matching elements from a server response or an HTML string. up.navigate() does the same with the defaults of a user navigation, like updating history and scrolling to the new content. up.reload() fetches a fresh copy of a fragment from the URL it was loaded from, and up.destroy() removes a fragment, with an optional animation.
Lookup functions like up.fragment.get() differ from document.querySelector(): they only see the current layer, ignore elements that are playing out their exit animation, and understand Unpoly's own selectors like :main or :origin. Elements marked [up-keep] are kept across updates. For low-level DOM utilities that complement the browser's native API, see up.element.
Your target selectors may use this pseudo-selector to replace the layer's topmost swappable element.
A pseudo-selector that matches the layer's main fragment.
Marks a target selector as optional.
To make a server request without changing a fragment, use the :none target.
Your target selectors may use this pseudo-selector to reference the origin element that triggered the change.
Returns the current context.
Destroys the given element or selector.
Elements are assigned the .up-destroying class before they are destroyed
or while they are being removed by a transition.
Sets an ETag for the fragment's underlying data.
Updates a selector on the current page with the same selector from the given HTML string.
Aborts requests targeting a fragment or layer.
This event is emitted when requests for an element were aborted.
Returns all elements matching the given CSS selector, but ignores elements that are being destroyed or that are being removed by a transition.
Returns the first element that matches the selector by testing the element itself and traversing up through ancestors in element's layers.
Configures defaults for fragment updates.
Returns whether the given root matches or contains the given selector or element.
This event is emitted after a page fragment was destroyed and removed from the DOM.
Returns the ETag of the content in the given element.
Returns the first element matching the given selector, but ignores elements that are being destroyed or that are being removed by a transition.
Returns the first fragment matching the given CSS selector.
When a page fragment has been inserted or updated, this event is emitted on the new element.
Returns whether the given fragment is both attached to the DOM and not currently in a destroy animation.
Returns whether Unpoly can derive a target selector for the given element.
This event is emitted before an existing element is kept during a render pass.
The up:fragment:kept event is emitted after an existing element has been kept during a render pass.
This event is emitted after the server response was loaded, but before the HTML is used to change a fragment.
Returns whether the given element matches the given CSS selector or other element.
This event is emitted when the device loses its network connection while rendering content.
Runs a callback when the given element or its ancestors in the same layer were aborted.
Runs a callback when the given element or its ancestors in the same layer were kept.
Returns the URL from which the given element was loaded.
Returns a list of a root element's descendants matching the given selector.
Returns the last modification time of the content in the given element.
Derives a CSS selector that matches the given element as good as possible.
Sets a unique identifier for this element.
Elements with an [up-keep] attribute will be kept when rendering.
Marks this element as the main fragment of your application layout.
Navigates to the given URL by updating a major fragment in the current page.
Replaces the given element with a fresh copy fetched from the server.
Replaces elements on the current page with matching elements from a server response or HTML string.
Replaces elements on the current page with corresponding elements from a new page fetched from the server.
When Unpoly inserts a fragment, the [up-source] attribute is automatically set
to the URL from which the fragment's HTML was loaded.
Clones a template element.
This event is emitted before a template is cloned.
Sets the time when the fragment's underlying data was last changed.
Fetches the given URL with JavaScript and replaces the current layer's main fragment with a matching fragment from the server response.
Tip Your coding agent can search these docs locally with the Unpoly agent skill