JSFiddle - React, Tailwind, and code Playground

by David_Knowles

HTML

<span class="obfuscate" data-mail-user="david" data-mail-domain="mydomain.nl">
										<span class="icon-wrapper">
											<i class="icon icon-envelope-alt" title="E-mail"></i>
										</span>
										<span class="value" itemprop="email">the link text1</span>
									</span>
									
									<span class="obfuscate" data-mail-user="david" data-mail-domain="theseconddomain.nl">
										<span class="icon-wrapper">
											<i class="icon icon-envelope-alt" title="E-mail"></i>
										</span>
										<span class="value" itemprop="email">second second link text</span>
									</span>

JavaScript

// -------- anti spam script
$(function(){
	var emailLink = $(".obfuscate"); //span
	var atsign = "@";
	if (emailLink.length > 0){
		for (var i = 0; i < emailLink.length; i++) {
		var user =  $(emailLink[i]).attr("data-mail-user");
		var domain =  $(emailLink[i]).attr("data-mail-domain");
		var addr = user + atsign + domain;
		var oldContent = $(emailLink[i]).html();
		var txt = $(oldContent).text();

		//var txt = $(stuff).find(".value").text();

		alert (txt);

			if (user.length > 0){ // optional alternative source for link text. Defaults to email address if no title is defined
					var linkTitle =  $(emailLink[i]).attr("title");
					if (linkTitle){
						var contacttxt = linkTitle;
					} else {
						var contacttxt = addr;
					}
			$(emailLink[i]).replaceWith("<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" + content + "<\/a>");//contacttxt
			}
		}
	}
});