window.addEventListener("load", () => { Array.from(document.getElementsByClassName("at")).forEach((elem) => { const span = elem.parentElement; // Replace (at) by @ elem.outerHTML = "@"; // Remove useless span const a = span.parentElement; // Correct text const data = span.getAttribute("data"); a.innerHTML = data.length > 0 ? data : span.textContent; // Change link a.setAttribute("href", a.getAttribute("href").replace(" at ", "@")); }); });