Edit this page

up.syntax up.hello(element, [options])
JavaScript function

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

All registered compilers and macros will be called with matches in the given element.

The up:fragment:inserted event is emitted on the compiled element.

Unpoly automatically calls up.hello()

When the page is manipulated using Unpoly functions or HTML selectors, Unpoly will automatically call up.hello() on new fragments:

let link = document.querySelector('a[href]')
let { fragment } = await up.follow(link)
// The fragment is already compiled. No need to call up.hello().

You only ever need to use up.hello() after creating DOM elements without Unpoly's involvement, for example:

  • Creating elements with document.createElement().
  • Setting the innerHTML property on an existing element
  • Parsing HTML into elements using browser APIs like DOMParser().
  • Elements created by other libraries

In this case compilers will not run automatically and some of Unpoly's own HTML selectors will not be active. We can address this by manually calling up.hello() on new elements:

let element = document.createElement('div')
element.innerHTML = '...'
// The element is not compiled yet. We must compile it manually:

Recompiling elements

It is safe to call up.hello() multiple times with the same elements. In particular every compiler function is guaranteed to only run once for each matching element.

If a new compiler is registered after initial compilation, that new compiler is run automatically on current elements.


element ElementorjQueryorstring

The root element of the new page fragment.

[options.data] Object optional experimental

Overrides properties from the new fragment's [up-data] with the given data object.

[options.meta={}] Object optional experimental

An object containing information about this compiler pass.

This typically contains { request, response, revalidating } properties.

It will be passed as a third compiler argument.

Return value

The compiled element

This website uses cookies to improve usability and analyze traffic.
I accept or learn more