0

Possible Duplicate:
Setting CSS pseudo-class rules from JavaScript

How do you do something equal to:

::selection {
    color: #FFF;
}

in javascript?

Community
  • 1
  • 1
Peter
  • 946
  • 9
  • 23
  • 1
    @Pumbaa80: `::selection` is not a pseudo-class, though the principle of using JS to modify the document styles does apply. – BoltClock Oct 06 '12 at 19:57

1 Answers1

2
.foobar::selection {
    color: #FFF;
}

element.className += " foobar";
I Hate Lazy
  • 47,415
  • 13
  • 86
  • 77
  • I can't add the change as an edit, because an edit requires 6+ characters to be edited... but it should be `+= " foobar"` because otherwise the previous classname would not be separated from the new one – Markus Unterwaditzer Oct 06 '12 at 17:39
  • @MarkusUnterwaditzer: Already updated, but you're right. Thanks. :) – I Hate Lazy Oct 06 '12 at 17:41
  • so there's no way to assign a (via js) generated color? – Peter Oct 06 '12 at 17:53
  • @peat-ar: To my knowledge, not without manipulating the style sheet. See the *possible duplicate* answer for more info. – I Hate Lazy Oct 06 '12 at 17:58
  • This doesn't answer the question, which was how to do it with javascript. This is a hybrid between CSS and JS. So how do we do this with Javascript? – sijpkes Sep 13 '22 at 06:32