| 1 | --- |
| 2 | title: "htmx:abort" |
| 3 | description: "Trigger to abort an ongoing request" |
| 4 | --- |
| 5 | |
| 6 | The `htmx:abort` event is a control event that, when fired on an element, aborts its ongoing request. |
| 7 | |
| 8 | ## When To Fire It |
| 9 | |
| 10 | Fire this event to programmatically cancel a request that's in progress. |
| 11 | |
| 12 | ## Event Detail |
| 13 | |
| 14 | Not applicable - this is a control event you trigger, not one you listen for. |
| 15 | |
| 16 | ## Example |
| 17 | |
| 18 | ```javascript |
| 19 | // Abort request on a specific element |
| 20 | htmx.trigger('#myElement', 'htmx:abort'); |
| 21 | |
| 22 | // Abort all requests in a container |
| 23 | document.querySelectorAll('#container [hx-get]').forEach(el => { |
| 24 | htmx.trigger(el, 'htmx:abort'); |
| 25 | }); |
| 26 | ``` |
| 27 | |
| 28 | The element's ongoing request will be cancelled when this event is received. |