I have to access CSS class by name, and the code below works. However if I try hui[\"myclass\"]
or hui[\".myclass\"]
instead of hui[0]
No, you can't access them by the selector - it's a simple list. You first had to build an index for it:
// assuming those are the right rules (ie from the right stylesheet)
var hui = document.styleSheets[0].rules || document.styleSheets[0].cssRules;
var styleBySelector = {};
for (var i=0; i
Of course this is not a fool-proof method, there could be
.myClass, .myOtherClass
and instead of blindly assigning the color
property you first should check for existence of the declaration.