From the course: Building Full-Stack Applications with HTMX

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Appending content

Solution: Appending content

(bright music) - [Instructor] Now that we've taken the test to append our server response into our target destination, let us solve it together. So, we have been given a button. And when this button is clicked, it is to append the server response to this results div, to the content already contained in this results div. So, let us get to solving that. The first thing we want to do is to make sure that we're targeting our div. So to do that, we're going to come here and say hx-target, then use our CSS selector to target our div with the id of results-container. That's good. So with that in place, we need to make sure that the response coming from the server is appended to what is already contained inside this div. We don't want it to swap the entire thing inside this div, we just want it to append to what's already existing inside this div. So for that, we need to add an hx-swap rule and we'll use the beforeend value. This will ensure that the response from the server is appended…

Contents