I know there are plugins that do this, but I need something pretty specific and I can't find anything.
I need a jQuery script that only change the mailto
link, and not the text of the link. For example:
<a href="person(at)exammple.com">Person's Email</a>
I need to display something else inside the link besides the actual e-mail address. The script I was trying to use is from this site.
Here's the script:
jQuery.fn.mailto = function() {
return this.each(function(){
var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
$(this).before('<a href="mailto:' + email + '" rel="nofollow" title="Email ' + email + '">' + email + '</a>').remove();
});
};
I think I need to replace the "email" variable with something else in between the <a>
tags, but I'm not sure with what. I'm still pretty new to jQuery.
Thanks.
How about this:
(function($) {
jQuery.fn.mailto = function() {
return this.each(function() {
var email_add = $(this).attr("href").replace(/\s*\(.+\)\s*/, "@");
var email_text = $(this).html();
$(this).before('<a href="mailto:' + email_add + '" rel="nofollow" title="Email ' + email_add + '">' + email_text + '</a>').remove();
});
};
})(jQuery);
$(document).ready(function() {
$(function() {
$('.email').mailto();
});
});
You can try it @ jsfiddle
var email = $(this).html().replace('@', '(at)');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With