The Dart Node API reference has a property style on Node elements. This allows me to programmatically set style properties. I'm trying to set the mouse cursor for when the mouse is dragging over an element. To do this I need to be able to set the style properties for the :active or :focus pseudoproperties. Is there a way for me to access these StyleDeclarations programmatically?
Asked
Active
Viewed 207 times
2 Answers
4
@Alexandre has pointed out how you can dynamically change style properties for pseudo-classes. I'll point out that in practice, I usually find it easier to dynamically change the class of an element such that it matches a pre-existing selector in my CSS file.
For example, if your CSS file includes:
.someClass:active {/* styles */}
then you can just add and remove someClass
from the element's classes dynamically as needed. Unless you have to do something complex to generate the styles, this is generally easier.

Darshan Rivka Whittle
- 32,989
- 7
- 91
- 109
-
Hmm, I guess the best thing to do is use an attribute selector. [attr=value] { style } since using classes will make for really awkward code when I want to switch the cursor a lot. (have to remember what classes to remove before adding new ones) – jz87 May 25 '13 at 17:42
2
You cannot set style properties for pseudo classes (same as javascript - see Setting CSS pseudo-class rules from JavaScript). You have to inject a Css rule in the stylesheet.

Community
- 1
- 1

Alexandre Ardhuin
- 71,959
- 15
- 151
- 132