Search code examples
jquerycsspseudo-class

Change attribute of CSS Pseudo classes (:hover) with jQuery


Is it even possible to change the pseudo classes with jQuery ? Is there any workaround for achieving this?


Solution

  • Well I created the following function to change my hover class

    var setPseudoClass = function (rule, prop, value)
        {
            var sheets = document.styleSheets;
            var slen = sheets.length;
            for (var i = 0; i < slen; i++)
            {
                var rules = document.styleSheets[i].cssRules;
                if (rules)
                {
                    var rlen = rules.length;
                    for (var j = 0; j < rlen; j++)
                    {
                        if (rules[j].selectorText && rules[j].selectorText.indexOf(rule) > 0)
                        {
                            alert(rules[j].selectorText);
                            rules[j].style[prop] = value;
                        }
                    }
                }
            }
        }