jQuery.MailTo

Simple jQuery plugin to hide email addresses from spambots. If the element is <a>, it will add the attribute href with respective mailto.


Download Forkit @ Github

Javascript

$('.email').mailto();

To avoid having to set data-host in multiple email addresses, you can set the default host in the plugin configuration:

$('.email').mailto({
host:'domain.com'
});

HTML

Basic Account name only (it will set the current host)

<a class="email" data-account="my.name"></a>

Link text Instead of email address

<a class="email" data-account="my.name" data-host="domain.com" data-text="My Email"></a>

Set host Server host

<a class="email" data-account="my.name" data-host="domain.com"></a>

Set subject Allows you to set the email subject

<a class="email" data-account="my.name" data-host="domain.com" data-subject="Information Request"></a>

Without 'mailto' hyperlink Not setting the href attribute

If the element is not a <a>, it will not set the href attribute.

<span class="email" data-account="my.name" data-host="domain.com"></span>

With child element

Append email to <a>

<a class="email" data-account="my.name" data-host="domain.com" data-subject="Information Request"><i class="glyphicon glyphicon-envelope"></i></a>

If you set the option prepend to true, email is inserted left from the existing child elements.

$('.email').mailto({
prepend:true
});
<a class="email" data-account="my.name" data-host="domain.com" data-subject="Information Request"><i class="glyphicon glyphicon-envelope"></i></a>

Literal If you prefer literal email addresses...

<a class="email">my dot name at domain dot com</a>

With a <span>Works with other html elements also

<span class="email">my dot name at domain dot com</span>