tags:

views:

22

answers:

1

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.

+2  A: 

You can give .error more specificity, like this:

input[type="text"].error{background:red;}​
//or if shared:
.error, input[type="text"].error{background:red;}​

You can give it a try here, with the same level of specificity, error will win because it's declared later in the CSS.

Nick Craver
The second approach was more appropriate for me as it's a shared style. Thanks for the quick response.Also, thanks for that link. Great tool!
DS
@DS - welcome :)
Nick Craver