Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the text selection color with jQuery. Demo not working

http://jsfiddle.net/uKdPM/

I've set the ::selection color in css, so when you highlight the text on the screen, the color of the text is pink. I'm trying to now override that color through jQuery when the page loads. Seems like it should be super simple. But it's not working for me.

like image 651
android.nick Avatar asked Feb 22 '23 03:02

android.nick


2 Answers

I believe if you want to achieve this kind of effect, you need to apply the color change based on a CSS class. I forked your jsfiddle, and heres the result

Although i think your question is interesting, im having a difficult time figuring where this can be put to practical use. Do you want to change the theme on the fly?

like image 187
Jan Dragsbaek Avatar answered Feb 24 '23 16:02

Jan Dragsbaek


According to this question you can't change the highlight color of a selection, because there isn't a DOM interface for manipulating pseudo classes. What you could do is to change the class of the element.

like image 26
kgiannakakis Avatar answered Feb 24 '23 17:02

kgiannakakis