Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
function updateBadge($badge, count) { if (count > 0) { $badge.text(count > 99 ? "99+" : count).show(); $badge.closest("[aria-label]").attr("aria-label", `Notifications: ${count} unread`); } else { $badge.hide(); $badge.closest("[aria-label]").attr("aria-label", "Notifications: none"); } } // Poll every 30 seconds setInterval(() => { $.getJSON("/api/notifications/count", ({ unread }) => { updateBadge($("#notif-badge"), unread); }); }, 30000);
Result
Open