Your Turn
Create a web page that asks the user to click one of two buttons to indicate whether they are happy or sad. When either button is clicked, display an alert with a corresponding message. If the user doesn’t click a button within five seconds (determined by using setTimeout), call the htmx.trigger function to trigger a “click” event on the sad button for them.
Create a web application that uses the htmx.ajax function to fetch and render a random quote every ten seconds.
One way to obtain a quote is to send a GET request to https://api.quotable.io/random. It returns a JSON object with a content property. This endpoint isn’t compatible with htmx because it returns JSON instead of text or HTML.
Create your own endpoint at the URL path
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