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 hiding existing children and inserting a new element as the only visible child. When the preview ends all changes will be reverted.
Tip
To visually remove elements during a preview, prefer hiding over detaching. See Prefer additive changes.
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>')
})
The element or selector to visually swap children of.
If omitted, the children of the targeted fragment will be swapped.
Tip Your coding agent can search these docs locally with the Unpoly agent skill