If you have control over the html that's being emitted, you might want
to take a look at the metadata plugin for this:
http://plugins.jquery.com/project/metadata
You can then do something like (not tested):
<a href="#" class="special {mLink:'partners', mSubject:'Partnership
Enquiry', mText:'Click to enquire'}"></a>
var h = window.location.host;
var data, mLink, mSubject, mText;
$(a.special).each(function(i,o){
data = $(o).metadata();
if(data.mLink && data.mSubject && data.mText){
o.href = 'mailto:' + data.mLink + '@' + h + '?subject=' +
data.mSubject;
$(o).text(data.mText);
}
});
- Jack
glawrie wrote:
I'm trying to set up a 'mailto' href within an existing tag. The tag is set
up to look like this before the jQuery
<a href="#" mLink="partners" mSubject="Partnership Enquiry" mText="Click
to enquire"></a>"
Our site is aliased to several domain names, the main point of the exercise
is to construct the link to reflect the domain name used to reach the site -
but as there are several such links, I'm hoping to generalise the content of
the link elements too, by making it possible to only have to specify the
mailbox, and subject of the mailto in a generic tag. Where the URL host
is 2gc.co.uk, the final tag I'm hoping for looks like this:
<a href="mailto:[EMAIL PROTECTED]
Enquiry">Click
to enquire</a>
The code I have to do this right now looks like this:
jQuery('a[mLink="partnerships"]').attr("href","mailto:partnerships@"+window.location.host
+"?subject=Partnership Enquiry").text("Click to enquire");
Clearly what I'd like to do is adjust this code to have the content of the
href to be drawn from mLink, and mSubject. But try as I might, I can't
work out a way to get jQuery to do this. My initial thought was to embed an
attribute request within the main query - kind of like this
jQuery('a[mLink="partnerships"]').attr("href","mailto:"+jQuery(this).attr('mLink')+"@"+window.location.host+"?subject=Partnership
Enquiry").text("Click to enquire")
But this returns '[EMAIL PROTECTED]" not "[EMAIL PROTECTED]" - similarly with
attempts to insert the subject text.
I am sure this is easy if you know how. I'd be very grateful for any
assistance from wiser minds on how to achieve what I'm attempting.
Thanks in advance for any help offered.