I am trying to set the download attribute on a link tag using jquery. In general I am using
<a type="button" id="pdf_modal_button" class="btn btn-primary" href="/download/x.pdf" download target="_blank">Download</a>
which downloads the pdf fine.
The problem arises when I generate a link:
<a type="button" id="pdf_modal_button" class="btn btn-primary" href=/download/>Download</a>
and then try to update the link with jquery:
var _href = $('#pdf_modal_button').attr("href");
$('#pdf_modal_button').attr("href", _href + '/x.pdf')
$('#pdf_modal_button').attr("download", true)
$('#pdf_modal_button').attr("target", "_blank")
it alters the link to download="true"
<a type="button" id="pdf_modal_button" class="btn btn-primary" href="/download/x.pdf" download="true" target="_blank">Download</a>
This causes the browser to open the pdf in a new tab and displays it, instead of just downloading.
Question is, how do I get it to just have a download attribute, and not download="true"
Setting the url in the download attribute doesn't work either.