Re: [SOLVED] Cloaking Email Addresses
Posted: Mon Feb 07, 2022 8:41 pm
I would also probably go with a separate script file instead of the inline javascript.
Give all the A elements a class name, eg "mail" and then use something like this:
Give all the A elements a class name, eg "mail" and then use something like this:
Code: Select all
// shortcut to use "d" as document (defined in the last line)
(d => {
// select all instances of A with classname "mail"
const mailz = d.querySelectorAll('a.mail');
// let's loop those items
mailz.forEach(cur => {
cur.addEventListener('click', function() {
this.href = this.href.replace(/AT/, '@').replace(/DOT/g, '.');
});
});
})(document);