Using jQuery 3.5.1 I try to change the ID on a button when another button is clicked, using $('#convertBtn').attr('id', 'convertBtnDownload');
but this is not working .. does anyone have an idea on why and how to fix this?
Working example:
$(document).ready(function() {
$("#convertBtn").click(function() {
console.log("Clicked")
$("#convertBtnSpinner").show();
$("#convertBtn").attr("disabled", true);
$("#convertBtnText").html("Genererer <span class='dot dot1'>.</span><span class='dot dot2'>.</span><span class='dot dot3'>.</span>");
document.documentElement.style.cursor = 'wait'
});
$("#convertBtnDone").click(function() {
console.log("Done")
$("#convertBtnSpinner").hide();
$("#convertBtn").attr("disabled", false);
$("#convertBtn").removeClass("btn-primary");
$("#convertBtn").addClass("btn-success");
$("#convertBtnText").html("Download PDF <i class='fas fa-download'></i>");
$('#convertBtn').attr('id', 'convertBtnDownload');
document.documentElement.style.cursor = 'default'
});
$('.convertBtnDownload').click(function() {
$('#resultLink').click();
});
});
.dot1 {
animation: visibility 1.5s linear infinite;
}
@keyframes visibility {
0% {
opacity: 1;
}
65% {
opacity: 1;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.dot2 {
animation: visibility2 1.5s linear infinite;
}
@keyframes visibility2 {
0% {
opacity: 0;
}
21% {
opacity: 0;
}
22% {
opacity: 1;
}
65% {
opacity: 1;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.dot3 {
animation: visibility3 1.5s linear infinite;
}
@keyframes visibility3 {
0% {
opacity: 0;
}
43% {
opacity: 0;
}
44% {
opacity: 1;
}
65% {
opacity: 1;
}
66% {
opacity: 0;
}
100% {
opacity: 0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/e3a6e5f796.js" crossorigin="anonymous"></script>
<button id="convertBtn" class="btn btn-primary" style="width: 220px;" type="button">
<span id="convertBtnSpinner" class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="display: none;"></span>
<span id="convertBtnText">Generate PDF <i class="far fa-file-pdf"></i></span>
</button>
<br>
<br>
<button id="convertBtnDone" class="btn btn-primary" type="button">Swap ID</button>