I have a MVC project that I'm using Ajax to update a section of a View that includes a FontAwesome 5 icon. FontAwesome is set using CSS class so I assumed that I could easily remove and then add the CSS for the icon. However, when I try making the CSS change through jQuery the CSS never get's set. The add/remove class works as expected on the regular CSS class I'm changing but not on the FA class valid-icon
.
This is the initial HTML:
@if (Model.VALID_FLAG == "Y")
{
<div class="validation__text-success" id="valid-flag>
<i class="fas fa-check-circle" id="valid-icon"></i> Yes
</div>
}
else
{
<div class="validation__text-danger" id="valid-flag>
<i class="fas fa-times-octagon" id="valid-icon"></i> No
</div>
}
This is the jQuery from the Ajax call.
var $html = $(response);
if ($html.hasClass('alert-success')) {
$("#valid-flag").text('Yes');
$("#valid-flag").removeClass().addClass('validation__text-success');
$("#valid-icon").removeClass().addClass('fas fa-check-circle');
}
else if ($html.hasClass('alert-danger')) {
$("#valid-flag").text('No');
$("#valid-flag").removeClass().addClass('validation__text-danger');
$("#valid-icon").removeClass().addClass('fas fa-times-octagon');
}