August 2024
Intermediate to advanced
186 pages
4h 3m
English
Sometimes the result of sending a request to an endpoint should be deleting the element that triggered the request. For example, in a todo app like the one shown in the following screenshot, clicking a button to delete a todo needs to send an HTTP request so the todo can be deleted on the server. Then the row describing the todo must be removed from the DOM.

The following HTML is used to describe each todo. Note the use of hx-swap="delete" and hx-target="closest div" on the button element. With those in place, the DELETE /todo/${id} endpoint doesn’t need to return any HTML and the div that contains the button will be deleted. ...
Read now
Unlock full access