Reputation: 1550
I have an input and a nearby link, and I would like to use JS to get the value from the input and insert it into the "mailto" element of the link. How can I accomplish this?
'<input class="an-input" type="text" id="'+$.fn.dataTable.Editor.safeId(conf.id)+'">'+
'<a class="ui-state-default inputButton an-button" href="mailto:">SEND</a>'
Upvotes: 0
Views: 63
Reputation: 103
$input = $(".an-input");
$input.next(".an-button").attr("href", "mailto:" + $input.val());
Upvotes: 1
Reputation: 10177
Use this
jQuery(function($){
var inputVal = $('input').val();
$('a').attr('href','mailto:'+ inputVal);
})
Upvotes: 1
Reputation: 1177
jQuery(function($){
$('.an-button').click(function(e){
$(this).attr('href', 'mailto:'+$('.an-input').val());
}
});
Upvotes: 1