Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation of svg oob swaps #2882

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions www/content/attributes/hx-swap-oob.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ Here is an example with an out of band swap of a table row being encapsulated in

Note that these template tags will be removed from the final content of the page.

### Slippery SVGs

Some element types, like SVG, use a specific XML namespace for their child elements. This prevents internal elements from working correctly when swapped in, unless they are encapsulated within a `svg` tag. To modify the internal contents of an existing SVG, you can use both `template` and `svg` tags to encapsulate the elements, allowing them to get the correct namespace applied.

Here is an example with an out of band swap of svg elements being encapsulated in this way:

```html
<div>
...
</div>
<template><svg>
<circle hx-swap-oob="true" id="circle1" r="35" cx="50" cy="50" fill="red" />
</svg></template>
<template><svg hx-swap-oob="beforebegin:#circle1">
<circle id="circle2" r="45" cx="50" cy="50" fill="blue" />
</svg></template>
```
This will replace circle1 inline and then insert circle2 before circle1.

Note that these template and svg wrapping tags will be removed from the final content of the page.

## Nested OOB Swaps

By default, any element with `hx-swap-oob=` attribute anywhere in the response is processed for oob swap behavior, including when an element is nested within the main response element.
Expand Down
Loading