0

I have form with input fields. The classes which are applied to input field are changed on click of submit button. I want to apply css rule if two css classes are applied with other css classes

Ex.

<input ng-model="formField.val" type="text" name="103" 
       class="form-control ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" 
       ng-disabled="readOnlyFlag" required="">

on click of submit button, the new css classes ng-invalid & ng-touched are applied with other css classes. I want apply css rule if ng-invalid & ng-touched are applied with other css classes.

 <input ng-model="formField.val" type="text" name="103" 
       class="form-control ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched ng-invalid ng-invalid-required" 
       ng-disabled="readOnlyFlag" required="">

1 Answer 1

2

Add styling for input when it has two classes:

input.ng-invalid.ng-touched{
  background:red;
  color:red;
}

Or if you want to use code use hasClass :

angular.element(myElement).hasClass('my-class');
angular.element(myElement).addClass('new-class');
angular.element(myElement).removeClass('old-class');

Code is copied from this question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.