Reputation: 45
Is possible to use jQuery to add this parameter to a mailto:
link?
?subject=Kontakt%20%7C%20ARCOTEL%20Wimberger%20Wien
This is the HTML:
<a data-ga-category="Direct contact" data-ga-action="Email" href="mailto:[email protected] " class="picons-envelope"><span class="pl-2">[email protected]</span></a>
I would like to get this output:
<a data-ga-category="Direct contact" data-ga-action="Email" href="mailto:[email protected]?subject=Kontakt%20%7C%20ARCOTEL%20Wimberger%20Wien" class="picons-envelope"><span class="pl-2">[email protected]</span></a>
Thanks so much!
Upvotes: 1
Views: 129
Reputation: 337691
You can use attr()
to update the value of an attribute. Provide a function to the method call which accepts the current value as an argument, and return the new value, like this:
$('a.picons-envelope').attr('href', (i, href) => href += '?subject=Kontakt%20%7C%20ARCOTEL%20Wimberger%20Wien');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<a data-ga-category="Direct contact" data-ga-action="Email" href="mailto:[email protected]" class="picons-envelope"><span class="pl-2">[email protected]</span></a>
Upvotes: 2