I am currently working on an MVC project where I am using Ajax to update a specific section of a View that contains a FontAwesome 5 icon. The FontAwesome icons are set using CSS classes, so my initial assumption was that it would be simple to remove and add the necessary CSS for the icon. However, when attempting to make the CSS change through jQuery, the CSS is not being set. The add/remove class functions as expected for the regular CSS class I am changing, but not for the FA class valid-icon
.
Here is the original HTML code:
@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 script used in 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');
}