< Back to my site

jQuery Email plugin

This jQuery plugin shows yet another way in which you can protect your email from spam. It appends an html anchor element with the email address created from the parameters you pass.
You can use is it by following these 3 steps:
  1. Include the jQuery library and jquery.email.js in your page like this:
    <head>
    	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" 
    		type="text/javascript"><script>
    	<script src="jquery.email.js" type="text/javascript"><script>
    </head>
  2. Create an html element where your email address will be displayed:
    <div id="emailHere">Email me here: </div>
  3. Call the function 'email(userName, domain, topLevelDomain)' like this:
    <script type="text/javascript">
    	$(document).ready(function(){
    	$('#emailHere').email('userName', 'gmail', 'com');});
    <script>
When the script is run, this anchor element gets appended to the div with id="emailHere":
<a href="mailto: userName@gmail.com" title="userName@gmail.com">userName@gmail.com</a>
The line below uses the plugin:
Email me here:

Another example

Another more complete example uses the noscript tag for those that do not have javascript enabled:
<div>
	My personal email address is: 
	<span id="personalEmail"> 
		<noscript> 
			<address>sonialfajardo88 at gmail dot com</address>
		</noscript>
	</span>
</div>
And:
<script type="text/javascript">
	$(document).ready(function(){
	$('#personalEmail').email('sonialfajardo88', 'gmail', 'com');});
<script>
If JavaScript is not enabled, this gets displayed:
My personal email address is:
sonialfajardo88 at gmail dot com
If JavaScript is enabled, this gets displayed:
My personal email address is: