Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ var htmx = (function() {
const pantry = find('#--htmx-preserve-pantry--')
if (pantry) {
for (const preservedElt of [...pantry.children]) {
const existingElement = find('#' + preservedElt.id)
const existingElement = find('#' + CSS.escape(preservedElt.id))
// @ts-ignore - use proposed moveBefore feature
existingElement.parentNode.moveBefore(preservedElt, existingElement)
existingElement.remove()
Expand Down Expand Up @@ -1926,7 +1926,7 @@ var htmx = (function() {
id = id.substring(1)
}
const oobValue = oobSelectValue[1] || 'true'
const oobElement = fragment.querySelector('#' + id)
const oobElement = fragment.querySelector('#' + CSS.escape(id))
if (oobElement) {
oobSwap(oobValue, oobElement, settleInfo, rootNode)
}
Expand Down Expand Up @@ -2001,7 +2001,7 @@ var htmx = (function() {
})

if (swapOptions.anchor) {
const anchorTarget = asElement(resolveTarget('#' + swapOptions.anchor))
const anchorTarget = asElement(resolveTarget('#' + CSS.escape(swapOptions.anchor)))
if (anchorTarget) {
anchorTarget.scrollIntoView({ block: 'start', behavior: 'auto' })
}
Expand Down
10 changes: 10 additions & 0 deletions test/attributes/hx-preserve.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,14 @@ describe('hx-preserve attribute', function() {
htmx._('handlePreservedElements')(fragment)
fragment.firstChild.innerHTML.should.equal('Old Content')
})

it('handles hx-preserve on elements with dotted IDs', function() {
this.server.respondWith('GET', '/test', "<div id='d1.sub' hx-preserve>New Content</div><div id='d2'>New Content</div>")
var div = make("<div hx-get='/test'><div id='d1.sub' hx-preserve>Old Content</div><div id='d2'>Old Content</div></div>")
div.click()
this.server.respond()
var preserved = document.querySelector('[id="d1.sub"]')
preserved.innerHTML.should.equal('Old Content')
byId('d2').innerHTML.should.equal('New Content')
})
})
9 changes: 9 additions & 0 deletions test/attributes/hx-select-oob.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ describe('hx-select-oob attribute', function() {
var div2 = byId('d2')
div2.innerHTML.should.equal('')
})

it('handles elements with IDs containing dots in hx-select-oob', function() {
this.server.respondWith('GET', '/test', "Normal Content<div id='d2.sub'><div id='d3'>New oob Content</div></div>")
var div1 = make("<div id='d1' hx-get='/test' hx-select-oob='#d2.sub'>Click Me!</div>")
make("<div id='d2.sub'><div id='d3'>Old Content</div></div>")
div1.click()
this.server.respond()
byId('d3').innerHTML.should.equal('New oob Content')
})
})