Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:wimbergerr@arcotel.com " class="picons-envelope"><span class="pl-2">wimbergerr@arcotel.com</span></a>

I would like to get this output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<a data-ga-category="Direct contact" data-ga-action="Email" href="mailto:wimbergerr@arcotel.com?subject=Kontakt%20%7C%20ARCOTEL%20Wimberger%20Wien" class="picons-envelope"><span class="pl-2">wimbergerr@arcotel.com</span></a>

Thanks so much!

>Solution :

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:wimbergerr@arcotel.com" class="picons-envelope"><span class="pl-2">wimbergerr@arcotel.com</span></a>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading