css-in-js

Setting CSS pseudo-class rules from JavaScript

瘦欲@ 提交于 2019-11-25 21:58:39
问题 I\'m looking for a way to change the CSS rules for pseudo-class selectors (such as :link, :hover, etc.) from JavaScript. So an analogue of the CSS code: a:hover { color: red } in JS. I couldn\'t find the answer anywhere else; if anyone knows that this is something browsers do not support, that would be a helpful result as well. 回答1: You can't style a pseudo-class on a particular element alone, in the same way that you can't have a pseudo-class in an inline style="..." attribute (as there is