admin管理员组

文章数量:1279207

I`ve got this link:

<a id="Link" href="mailto:[email protected]?subject=I-Drain Bestellung&body="></a>

Now i want to append data from an form element after &body="

So for example the first time it changes to &body="New text , and the next time it changes to &body="New text , Another text.

How can i do this? Can´t get it to work.. thank you :)

I`ve got this link:

<a id="Link" href="mailto:[email protected]?subject=I-Drain Bestellung&body="></a>

Now i want to append data from an form element after &body="

So for example the first time it changes to &body="New text , and the next time it changes to &body="New text , Another text.

How can i do this? Can´t get it to work.. thank you :)

Share Improve this question edited Jun 11, 2013 at 14:51 Adil Shaikh 44.7k17 gold badges95 silver badges112 bronze badges asked Jun 11, 2013 at 14:50 Marc SterMarc Ster 2,3166 gold badges36 silver badges64 bronze badges 4
  • 1 More code please so we can adjust it to your needs – lukas.pukenis Commented Jun 11, 2013 at 14:52
  • Please post the code which you have tried that did not work. – James Montagne Commented Jun 11, 2013 at 14:53
  • Duplicate: stackoverflow./questions/2805742/… – Akrasiac Commented Jun 11, 2013 at 14:56
  • i´ve read this before, but solutions didn´t work for my case. – Marc Ster Commented Jun 11, 2013 at 14:58
Add a ment  | 

4 Answers 4

Reset to default 7

You change the attribute of the link:

var link = $('#Link');
link.attr('href', link.attr('href') + 'your text');

You can use pure JS :

var el = document.getElementById('link');
el.href += 'some string';

When possibile, always try to use JS over jQuery, usually, it will provide better performance since it reduce the number of functions call.

For example, you can do it with:

var form = $('.form_element').val();
var el = $('a#Link').prop('href');

el.prop('href', el.prop('href')+form);
$('#Link').attr('href',$('#Link').attr('href')+"New Text")

本文标签: javascriptAppend to the end of an href value with jqueryStack Overflow