← All examples

Swap modes

Every button fetches the same HTML fragment. Only minu-swap changes where the fragment lands relative to its target.

Want state preserved across a swap? See Morph vs innerHTML.

Target

Replace children.

Target

Replace this box.

Target

Insert before.

Target

Insert first child.

Target

Append as last child.

Target

Insert after.

Target

Remove this box.

Target

Fetch, but do not swap.

Reset all boxes Last event: —

What each mode does

ModeResult
innerHTML (default)Replace the target’s children.
outerHTMLReplace the target itself.
beforebeginInsert before the target.
afterbeginInsert as the target’s first child.
beforeendInsert as the target’s last child.
afterendInsert after the target.
deleteRemove the target, ignore the response body.
noneFetch but do not swap; useful for side effects/events.

How it works

  1. Minu resolves the button’s target before the request.
  2. The response is sanitized, then swap() applies the requested mode.
  3. delete and none still fire the normal request and content events.
  4. outerHTML and delete remove their target; reload to reset those boxes.
<button minu-get="/demo/fragment"
        minu-trigger="click"
        minu-target="#swap"
        minu-swap="beforeend">
    Append
</button>

<div id="swap">…</div>