Edit this page

up.Preview up.Preview.prototype.swapContent([element], newContent)
Instance method

This feature is experimental. Please share your experiences so we know what to keep or change.

Visually replaces the children of an element with new content for the duration of this preview.

The visual effect is achieved by hidden existing children and inserting a new element as the only visible child. When the preview ends all changes will ber reverted.

Tip

To visually remove elements during a preview, prefer hiding over detaching. See Prefer additive changes.

Example

This preview (visually) replaces the children of the targeted fragment with a .spinner element:

up.preview('spinner', function(preview) {
  preview.swapContent('<span class="spinner">Please wait...</span>')
})

To swap the content of another element, pass it as a first reference argument:

up.preview('spinner', function(preview) {
  preview.swapContent('body', '<span class="spinner">Please wait...</span>')
})

Parameters

[element=this.fragment] Element|string optional

The element or selector to visually swap children off.

If omitted, the children of the targeted fragment will be swapped.

newContent Element|string

The new content to insert.

You may pass an Element, a CSS selector or a snippet of HTML.

If the given element is a template, it will be cloned before insertion.