'Add parameter to "mailto:" by Jquery

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!



Solution 1:[1]

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>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rory McCrossan