开发者

jQuery: How to override pseudo style?

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开发者_JS百科 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 .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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜