alpinejs-notify
Version:
Simple notifications in your projects using Alpine JS 🙋♀️
18 lines (14 loc) • 569 B
JavaScript
export function createNotification(wrapperId, templateId, notificationText) {
const notificationWrapper = document.getElementById(wrapperId)
const notificationTemplate = document.getElementById(templateId)
const notificationComponent = new DOMParser().parseFromString(
notificationTemplate.innerHTML.replace(
'{notificationText}',
notificationText
),
'text/html'
).body.firstChild
notificationWrapper.appendChild(notificationComponent)
notificationComponent.setAttribute('data-notify-show', true)
return notificationComponent
}