title: How to add and remove CSS classes based on validation errors on client side?
body: <p>Regarding .net core mvc, how do I add and remove classes for <code>&lt;span asp-validation-for=&quot;Input.FirstName&quot;&gt;</code> based on a validation error or even between different errors?</p>
  <pre><code>            &lt;div class=&quot;form-group offset-sm-2 col-sm-8&quot;&gt;
                  &lt;label asp-for=&quot;Input.FirstName&quot; class=&quot;control-label register-heading-style&quot;&gt;&lt;/label&gt;
                  &lt;input asp-for=&quot;Input.FirstName&quot; class=&quot;form-control form-control-valid rounded-0&quot; placeholder=&quot;John&quot; /&gt;
                  &lt;span asp-validation-for=&quot;Input.FirstName&quot; id=&quot;FirstNameError&quot; class=&quot;text-danger form-control-invalid invalid-bg&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
  </code></pre>
  <p>Is there a way in JS perhaps to check for errors on input (the errors that are automatically displayed under <code>asp-validation-for=&quot;Input.FirstName&quot;</code>)?</p>
  <p>Thank you</p>