Setting background color with JavaScript breaks the CSS hover behavior

前端 未结 4 1344
你的背包
你的背包 2021-01-15 14:47

I\'m trying to create a menu where the currently selected (clicked) element has a different background color than the other elements (I\'m trying to achieve this using JavaS

4条回答
  •  天涯浪人
    2021-01-15 15:23

    The jQuery css() method maps onto the style property which maps onto the style attribute.

    Rules inside a style attribute are more specific then rules in a stylesheet, so will always come after them in the cascade.

    Instead of altering the CSS on the element directly, alter it by changing the classes the element belongs to and having a pre-prepared stylesheet.

提交回复
热议问题