I have an ajax call and at the end of it I'm setting href
for anchor tag and want to click it but am unable to do so. Here is my code:
<div>
<a id="hypSendEmail">email</a>
</div>
$("body").on("click", "#btnPopulateEmails", function () {
var $form = $("#btnPopulateEmails").parents('form');
$.ajax({
type: "POST",
url: url,
async: true,
data: $form.serialize()
}).done(function (data) {
var json = data,
obj = JSON.parse(json);
if (obj.MessageType == "success") {
$("#hypSendEmail").attr('href', obj.MessageLink);
$("#hypSendEmail").trigger("click");
//$("#hypSendEmail").click();
$.colorbox.close();
}
if (obj.MessageContent != null) {
//do something else
}
});
return false;
});
I believe I have to somehow use .on
function to trigger that click maybe? Please help. My purpose is to populate hyperlink with mailto & click it automatically. I tried doing this on code behing using Process.Start()
& Response.Redirect()
, but both failed, so now I'm trying my luck here. It does populate href
tag on my anchor tag, but just doesn't click it.