Edit this page

API Custom JavaScript
module up.script

The up.script package lets you pair HTML elements with JavaScript behavior.

Unpoly encourages you to migrate all your custom JavaScript from DOMContentLoaded callbacks to compilers. This will make sure they run both at page load and when a new fragment is inserted later. See Migrating legacy JavaScripts for details.


Guides

Features

Essentials

All features

HTML
[up-asset] stable

Tracks an element as a frontend asset, usually JavaScripts and stylesheets.

JS
up:assets:changed stable

This event is emitted when frontend code changes while the application is running.

JS
up.compiler(selector, [options], compiler) stable

Registers a function to be called when an element with the given selector is inserted into the DOM.

JS
up.$compiler(selector, [options], compiler) deprecated

Registers a function to be called when an element with the given selector is inserted into the DOM. The function is called with each matching element as a jQuery object.

JS
up.data(element) stable

Returns the data attached to the given element.

HTML
[up-data] stable

Attaches structured data to an element, to be consumed by a compiler or event handler.

JS
up.destructor(element, destructor) stable

Registers a function to be called when the given element is destroyed.

JS
up.hello(element, [options]) stable

Manually compiles a page fragment that has been inserted into the DOM by external code.

JS
up.macro(selector, options, macro) stable

Registers a compiler that is run before all other compilers.

JS
up.$macro(selector, options, macro) deprecated

Registers a compiler that is run before all other compilers. The compiler function is called with each matching element as a jQuery object.

JS
up.script.config stable

Configures defaults for script handling.