5

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

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Sabby62
  • 1,707
  • 3
  • 24
  • 37

2 Answers2

2

Try to create a class selector to your CSS, and toggle the class on and off for the element you would like to change style/anything when you hover over it.

Here are other suggestions: Setting CSS pseudo-class rules from JavaScript

Dynamic CSS pseudo class styles with jQuery

Community
  • 1
  • 1
yvonnezoe
  • 7,129
  • 8
  • 30
  • 47
  • Definitely this. Using Javascript to change individual CSS properties is very messy.. just switch the class! – benastan May 14 '13 at 00:27
  • The problem with changing the class is that you might be using a color-picker. – Bing Feb 05 '14 at 20:49
0

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;
                    }
                }
            }
        }
    }
Sabby62
  • 1,707
  • 3
  • 24
  • 37