Here is a jQuery snippet that can protect email addresses from email harvesters. All you need to do is to inlcude .mail class to your “mailto:” html links like the example below.
1 |
<a href="mailto:peter_[at]_example.com"> peter_[at]_example.com </a> |
1 2 3 4 5 6 7 8 9 |
jQuery(document).ready(function(){ mailtoellements = jQuery("a[href^='mailto:']"); mailtoellements.each(function(item){ mailto = jQuery(this).attr('href'); jQuery(this).attr('href',mailto.replace(/_\[\at\]\_/gi,"@")); email = jQuery(this).html(); jQuery(this).html(email.replace(/_\[\at\]\_/gi,"@")); }); }); |
line 2: Gather all the elements with the matched criteria line 3: Iterate on these elements line 4: on each […]