Read :hover pseudo class with javascript

前端 未结 5 1531
时光说笑
时光说笑 2020-11-29 11:55

I made a function that overwrite the the :hover of some elements on a page. It fades between the normal and the :hover effect. That for i had to create a .hover class in my

5条回答
  •  没有蜡笔的小新
    2020-11-29 12:38

    If there are any people here who use the questions accepted answer but it won't work, here's a nice function that might:

    function getPseudoStyle(id, style) {
        var all = document.getElementsByTagName("*");
        for (var i=0, max=all.length; i < max; i++) {
            var targetrule = "";
            if (all[i].id === id) {
                if(all[i].selectorText.toLowerCase()== id + ":" + style) { //example. find "a:hover" rule
                    targetrule=myrules[i]
                }
            }
            return targetrule;
        }
    }
    

提交回复
热议问题