5

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

3
  • it is not possible to use jQuery for such cases Commented May 13, 2013 at 23:53
  • A few days ago I found a jQuery-style library to access stylesheets, but now I can't find it again, all I find are stylesheet switchers. Commented May 13, 2013 at 23:56
  • Not sure I understand. Could you elaborate? What exactly do you want to change? Commented May 13, 2013 at 23:56

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Definitely this. Using Javascript to change individual CSS properties is very messy.. just switch the class!
The problem with changing the class is that you might be using a color-picker.
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;
                    }
                }
            }
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.