Skip to content

Instantly share code, notes, and snippets.

View maekoos's full-sized avatar

Markus Stensiö maekoos

  • Göteborg
  • 07:55 (UTC +01:00)
View GitHub Profile
@maekoos
maekoos / htmx-toast.js
Last active October 14, 2024 09:49
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';