From the course: HTMX Essential Training
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Solution: Selecting HTML elements - HTMX Tutorial
From the course: HTMX Essential Training
Solution: Selecting HTML elements
(upbeat music) - [Instructor] Let's make some adjustments to our server.js so we can start to handle this request. So the first thing that we're going to do is make an adjustment to our if statement here. So we'll first say "else if" for this method on line 9, and then we'll say "if" here. So we'll say "if request.URL starts with" and we'll use "change-color", "/change-color" specifically. Now what this is going to do is if we use the attribute correctly, let's put these side by side. If we use the attribute correctly here in our select element, this is going to, when I send that request to change the color, this will be the handler. So we'll say "const url = new URL", and this is going to concatenate the request URL with the "http://${req.headers.host}". Then we'll say "const_colorClass" "url.searchParams.get('color')" or an empty string. And then we'll write the headers. So we'll say "res.writeHead(200)", "Content-Type", "text/plain", and then we'll say "res.end". And here what we…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.