Skip to content

Instantly share code, notes, and snippets.

@aron
Created January 16, 2009 17:41
Show Gist options
  • Save aron/48026 to your computer and use it in GitHub Desktop.
Save aron/48026 to your computer and use it in GitHub Desktop.
Simple jQuery plugin to fill in mailto links.
$(document).ready(function(){
$("a[href^=mailto]").emailSwitcher();
});
// Switches emails in the form <a href="mailto:">bill at ben dot com</a>
// to <a href="mailto:bill@ben.com">bill@ben.com</a>.
$.fn.emailSwitcher = function () {
var regex = /^([^\s]+)\s+at\s+([^\s]+)\s+dot\s+([^\s]+)$/gi;
this.each(function () {
var $this = $(this),
email;
if ($this.text().match(regex)) {
email = $(this).text().replace(regex, '$1@$2.$3');
$this.attr('href', 'mailto:' + email).text(email);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment