future-appointment-69775
05/27/2023, 12:58 PMproud-librarian-99598
05/27/2023, 2:16 PMhx-swap="afterend"
to it, the result is that the number is added 2 times in the HTML for each click of the button:
<!-- load demo environment -->
<script src="https://demo.htmx.org"></script>
<!-- post to /foo -->
<button hx-post="/foo" hx-target="#result" hx-swap="afterend">
Count Up
</button>
<output id="result"></output>
<!-- respond to /foo with some dynamic content in a template tag -->
<script>
globalInt = 0;
</script>
<template url="/foo" delay="500"> <!-- note the url and delay attributes -->
${globalInt++}
</template>
https://cdn.discordapp.com/attachments/725789747212976259/1112021603207880795/image.png▾
mysterious-toddler-20573
05/27/2023, 2:18 PMproud-librarian-99598
05/27/2023, 2:23 PMmysterious-toddler-20573
05/27/2023, 2:54 PMswift-spring-80795
05/27/2023, 8:03 PMfreezing-waitress-26396
05/27/2023, 8:08 PMgreat-cartoon-12331
05/27/2023, 8:10 PMswift-spring-80795
05/27/2023, 8:12 PMgreat-cartoon-12331
05/27/2023, 8:14 PMswift-spring-80795
05/27/2023, 8:19 PMripe-action-67367
05/27/2023, 8:25 PMripe-action-67367
05/27/2023, 8:25 PMripe-action-67367
05/27/2023, 8:27 PMswift-spring-80795
05/27/2023, 8:28 PMswift-spring-80795
05/27/2023, 8:31 PMgreat-cartoon-12331
05/27/2023, 8:36 PMswift-spring-80795
05/27/2023, 8:39 PMripe-action-67367
05/27/2023, 8:47 PMswift-spring-80795
05/27/2023, 8:50 PMgreat-cartoon-12331
05/27/2023, 8:52 PMrefined-waiter-90422
05/28/2023, 2:30 AMrefined-waiter-90422
05/28/2023, 2:38 AMrefined-waiter-90422
05/28/2023, 2:39 AMswift-spring-80795
05/28/2023, 3:13 AMmysterious-toddler-20573
05/28/2023, 3:40 AMgreat-cartoon-12331
05/28/2023, 3:41 AMnice-cpu-16963
05/28/2023, 8:53 AMgray-morning-3453
05/28/2023, 7:22 PMprehistoric-air-9306
05/28/2023, 7:23 PMhtml
<div>
<button onclick="this.parentElement.remove()">Delete</button>
</div>
The closest I can find is (where /returns-empty is a non-404 endpoint I make that returns an empty string):
html
<div class="target">
<button hx-target=".target" hx-delete="/returns-empty">Delete</button>
</div>
But ideally I'd love to be able to skip the request and just do something like this
html
<div class="target">
<button hx-target=".target" hx-response="">Delete</button>
</div>
(hx-response is just one idea I had for something that could be used as the value if no hx-get hx-post etc exists, but any method to accomplish the task would work well)