Your Turn
Before moving on, try the following things to make sure you understand how to perform out-of-band swaps and trigger events.
-
Create a web app that displays two paragraphs and a button. When the button is clicked, send a GET request to an endpoint you define. In the endpoint, return two new paragraphs that use the hx-swap-oob attribute to replace both of the paragraphs. You’ll need to assign unique ids to each of the paragraphs.
-
Create a web app that displays a button. When the button is clicked, send a GET request to an endpoint you define. In the endpoint, set the HX-Target response header so an event will be dispatched in the client. Use the hx-on attribute to listen for the event. Verify that the event was received by calling alert(’I ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access