Hide email address using jQuery

I know there are plugins that do this, but I need something quite specific, and I can’t find anything.

I need a jQuery script that only changes the mailto link, not the link text. For example:

<a href="person(at)exammple.com">Person Email</a>

I need to show something else inside the link besides the actual email address. script I tried to use this 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 between the <a> tags, but I'm not sure what. I'm still pretty new to jQuery.

Thanks.

+7
source share
3 answers

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 @ jsfiddle

+8
source

var email = $ (this) .html (). replace ('@', '(at)');

+1
source

I have jq-plug-in i that can help. See violin (working demo)

Keep in mind that the plugin ends with / * -------------------------------------- - ---------------------------------- * /

To use ez:

 $("#domElementID").jqMailTo({ // Not all of these options are a must except for the address address: [" Saab@test.net "," Volvo@test.net "," BMW@test.net "], // can also be as simple as 1 string, exp -> address:' BMW@test.net ', label: 'testLabel', subject: 'This is a subject', body: 'This is a Body section', cc: ' aCC@test.net ', bcc: ' theBCC@test.com ' }); 
0
source

All Articles