I have a button that will run an ajax process. but first I add a spinner icon and disable it so that the button won't be clicked multiple times while the ajax is not completed.
I succeeded in adding the icon with this code:
$('#button1').append('<i class="fa fa-spinner fa-spin"></i>');
and after googling for a little, I found out that I need to use .remove()
to remove an element with jquery. then why won't this code remove the icon?
$('#button1').remove('.fa');
$('button').click(function() {
alert('asd');
$(this).remove('.fa');
});
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button">
submit
<i class="fa fa-spinner"></i>
</button>