Control how fetched content replaces existing content with swap strategies.

Swap Strategies

Use data-swap to control how content is inserted:

StrategyDescriptionUse Case
innerReplace innerHTML (default)Most page content
outerReplace entire elementUpdating a component
prependInsert at beginningNew notifications
appendInsert at endInfinite scroll
beforeInsert before elementAdd row above
afterInsert after elementAdd row below
deleteRemove elementDelete item from list
noneDon't swapFire-and-forget requests

Examples

Inner (Default)

Append (Infinite Scroll)

Prepend (Notifications)

Delete

Fragment Selection

Use data-select to extract a portion of the response:

This fetches /full-page but only inserts the #sidebar-content element from the response.

Target Options

CSS Selector

Self

Out-of-Band Swaps

Update multiple elements from a single response using data-oob:

Elements with data-oob are swapped into matching elements by ID, regardless of the main target.

Cascade Reminder: data-swap inherits from ancestors. Set a default on a container, override only where needed.