So here’s the summary
CSS:
input[type="text"]:focus{background:blue;}
.error{background:red;}
Javascript:
if(error){ $('#elementid').focus().addClass('error');
Problem:
The field goes red then goes blue immediately and stays blue when it is
in focus.
How do I make the ‘error’ class take precedence, when the javascript executes and the focus goes to the ‘elementid’ field and not the :focus class.
You can give
.errormore specificity, like this:You can give it a try here, with the same level of specificity,
errorwill win because it’s declared later in the CSS.