Skip to content

Instantly share code, notes, and snippets.

View maekoos's full-sized avatar

Markus Stensiö maekoos

View GitHub Profile
@maekoos
maekoos / htmx-toast.js
Last active July 18, 2024 22:04
Server sent toasts in HTMX
htmx.on("htmx:afterRequest", (e) => {
const toast = e.detail.xhr.getResponseHeader('HX-Toast');
// Can be expanded with HX-Toast-Type or similar to specify success, warning, info, etc
if(toast) {
const el = document.createElement('span');
el.innerText = toast;
el.style.position = 'fixed';
el.style.top = '10px';
// Right aligned:
// el.style.right = '10px';