| 1 | --- |
| 2 | title: "hx-select-oob" |
| 3 | description: "Picks response elements to swap into the page by ID" |
| 4 | --- |
| 5 | |
| 6 | The `hx-select-oob` attribute allows you to select content from a response to be swapped in via an out-of-band (OOB) |
| 7 | swap, separate from the main content swap. |
| 8 | |
| 9 | This is useful when you want to update multiple parts of the page from a single response, where some updates happen in |
| 10 | the target element and others happen in different locations. |
| 11 | |
| 12 | ## Syntax |
| 13 | |
| 14 | The value is a comma-separated list of CSS selectors. Each selector can optionally be followed by a colon and a swap |
| 15 | strategy. |
| 16 | |
| 17 | ```html |
| 18 | <button hx-get="/example" hx-select-oob="#alert,#sidebar:afterbegin"> |
| 19 | Click Me |
| 20 | </button> |
| 21 | ``` |
| 22 | |
| 23 | ## Basic Usage |
| 24 | |
| 25 | ```html |
| 26 | <button hx-get="/update" hx-select-oob="#notification"> |
| 27 | Update |
| 28 | </button> |
| 29 | |
| 30 | <!-- Response would contain: --> |
| 31 | <!-- <div id="notification">New notification!</div> --> |
| 32 | ``` |
| 33 | |
| 34 | The element with id `notification` in the response will be swapped into the page at the location of the existing element |
| 35 | with that id. |
| 36 | |
| 37 | ## With Swap Strategies |
| 38 | |
| 39 | You can specify different swap strategies for each selected element: |
| 40 | |
| 41 | ```html |
| 42 | <button hx-get="/update" |
| 43 | hx-select-oob="#alert:afterbegin,#count:innerHTML"> |
| 44 | Update Multiple |
| 45 | </button> |
| 46 | ``` |
| 47 | |
| 48 | ## Notes |
| 49 | |
| 50 | * Works similarly to `hx-swap-oob` in the response, but driven from the request side |
| 51 | * The selected elements must have an `id` attribute to identify where to swap them |
| 52 | * If no swap strategy is specified, the default is `outerHTML` |
| 53 | * Can be combined with [`hx-select`](/reference/attributes/hx-select) to also select the main content |
| 54 | |
| 55 | ## See Also |
| 56 | |
| 57 | * [`hx-swap-oob`](/reference/attributes/hx-swap-oob) |
| 58 | * [`hx-select`](/reference/attributes/hx-select) |
| 59 | * [`<hx-partial>`](/docs#partials-hx-partial) |