document.querySelectorAll('[data-delete]').forEach((el) => { el.addEventListener('click', (e) => { if (confirm('Are you sure? This cannot be undone.')) { let postId = e.target.dataset.delete; fetch(`/posts/${postId}`, { method: 'DELETE', }).then((r) => { r.json().then((data) => { if (data.success) { window.location = '/'; } }); }); } }); });