After running this: $('.bar').css({'color':'#fff'}); hover for .bar stops working. Why?
Also, $('.bar:hover').css({'color':'#fff'}); doesn’t change hover’s color too, why? What am I missing?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You haven’t defined what you mean by “hover”, but if you’re talking about CSS
:hover, then it’s because inline styles (as set by.css()override stylesheet styles.You can add
!importantto your CSS definition to override the inline.I don’t believe this works with older IE though.
DEMO: http://jsfiddle.net/hh4NJ/1/
Another (and arguably better) solution would be to use
.addClass()instead of.css()to change the style. Then you can take care of all of it in your CSS (except for adding/removing the class of course).DEMO: http://jsfiddle.net/hh4NJ/2/
Regarding your update, you can’t use pseudo selectors like
:hoverfor DOM selection.