Skip to content

Commit a1a5dc0

Browse files
committed
allow textContent for oobSwaps
1 parent 9dcb028 commit a1a5dc0

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/htmx.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,8 +1913,8 @@ var htmx = (function() {
19131913
const settleInfo = oobSettleInfo || makeSettleInfo(target)
19141914

19151915
// For text content swaps, don't parse the response as HTML, just insert it
1916-
if (typeof content === 'string' && swapSpec.swapStyle === 'textContent') {
1917-
target.textContent = content
1916+
if (swapSpec.swapStyle === 'textContent') {
1917+
target.textContent = typeof content === 'string' ? content : content.textContent
19181918
// Otherwise, make the fragment and process it
19191919
} else {
19201920
/** @type DocumentFragment|ParentNode */

test/attributes/hx-swap-oob.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,13 @@ describe('hx-swap-oob attribute', function() {
481481
done()
482482
}, 30)
483483
})
484+
485+
it('handles textContent swap style', function() {
486+
this.server.respondWith('GET', '/test', '<div id="d2" hx-swap-oob="textContent"><p>Swapped16</p><p>!</p></div>')
487+
var div = make('<div hx-get="/test">click me</div>')
488+
var div2 = make('<div id="d2"><div>')
489+
div.click()
490+
this.server.respond()
491+
div2.innerHTML.should.equal('Swapped16!')
492+
})
484493
})

www/content/attributes/hx-select-oob.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ This button will issue a `GET` to `/info` and then select the element with the i
2727
which will replace the entire button in the DOM, and, in addition, pick out an element with the id `alert`
2828
in the response and swap it in for div in the DOM with the same ID.
2929

30-
Each value in the comma separated list of values can specify any valid [`hx-swap`](@/attributes/hx-swap.md)
31-
strategy by separating the selector and the swap strategy with a `:`, with the strategy otherwise defaulting to `outerHTML`.
30+
Each value in the comma-separated list consists of a CSS selector used to locate an element in the response. Optionally, this can be followed by a colon `:` and any valid [`hx-swap-oob`](@/attributes/hx-swap-oob.md) value; if omitted, the swap strategy defaults to outerHTML. As with `hx-swap-oob`, the target element for the swap will default to the element’s ID, but this can be overridden if needed.
3231

3332
For example, to prepend the alert content instead of replacing it:
3433

0 commit comments

Comments
 (0)