android.nick
android.nick

Reputation: 11215

Jquery: possible to change the text selection color in a textarea with jquery? css doesn't work :(

textarea::selection {
background:#0099ff;}

That's how you specify a text selection color for chrome in CSS, i know it's different for different browsers but I wanted to know if there's a way to change the selection color inside of a textarea, because the code above wont work for chrome, now, in the code above if i changed textarea to p then it would work on all the paragraphs. I noticed that the code above does work if I select the ENTIRE textarea, but not when selecting text in it.

Upvotes: 1

Views: 1532

Answers (2)

dsrdakota
dsrdakota

Reputation: 2583

Not 100% true. It should work in paragraphing, but not any other element. Try:

See here for a related answer to a related question.

Specifications

The ::selection CSS pseudo-element was drafted for CSS Selectors Level 3 but removed > before it reaches the Recommendation status. Despite this, it's implemented in some >browsers, which will probably retain experimental support for it.

Right now, the ::selection CSS pseudo-element is not in any specification on the standard track.

Browser compatibility

Chrome: 1.x, Firefox (Gecko): 1.0 (with -moz), Internet Explorer: 9, Opera: 9.5 or later, Safari: 1.1

Note: As said in that answer in the link, removed from the draft.

So basically, you can:

  • Change non-selection color

but you can't:

  • Change the selection color (not yet)

Note: Not all stuff in this answer maybe true.

Upvotes: 2

android.nick
android.nick

Reputation: 11215

you can't change the selection color for a textarea, you can only change it for non-input objects.

Upvotes: 1

Related Questions