Is it even possible to change the pseudo classes with jQuery ? Is there any workaround for achieving this?
Asked
Active
Viewed 7,139 times
5
-
it is not possible to use jQuery for such cases – Sushanth -- May 13 '13 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. – Barmar May 13 '13 at 23:56
-
Not sure I understand. Could you elaborate? What exactly do you want to change? – VVV May 13 '13 at 23:56
2 Answers
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
-
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