I am using Font Awesome and jQuery in an experiment, after an animation, the jQuery replaces a loading icon in a list by a check, and the text changes too. However, when I remove the jQuery replaceWith
method, the icon stays:
HTML:
<ul class="fa-ul">
<li><i class="fa-li fa fa-spinner fa-spin" id = "ToDo1"></i>Downloading</li>
<li><i class="fa-li fa fa-square" id = "ToDo2"></i>text</li>
<li><i class="fa-li fa fa-square" id = "ToDo3"></i>text</li>
<li><i class="fa-li fa fa-square" id = "ToDo4"></i>text</li>
</ul>
jQuery:
setTimeout(function() {
$("#ToDo1").removeClass("fa-spin fa-spinner");
$("#ToDo1").addClass("fa-check-square");
$("li:first").replaceWith("Download Complete");
$("#ToDo2").addClass("fa-spin fa-spinner");
}, 2000);
Result:
before:
After jQuery replaceWith
What is the problem?
.text()
instead of.replaceWith()
– YpresreplaceWith
– Degeneracy.replaceWith()
will replace the whole<li>
element with what you pass it, so that gets rid of the text that was there before and it gets rid of the icon. – Sw