Change color placeholder in Javascript for Chrome

As said here: Change the color of the HTML5 input placeholder using CSS , Chrome does not support the color of the CSS property for input placeholders.

But there is a property called -webkit-input-placeholder . If I put on my CSS:

 #MyInput::-webkit-input-placeholder { color: blue; } 

It works. But how can I do this using Javascript (or jQuery)?

+4
source share
1 answer

Define it in CSS as it is, but make it #MyInput.blue-placeholder::-webkit-input-placeholder and add / remove the blue placeholder class using jQuery.

 #MyInput.blue-placeholder::-webkit-input-placeholder { color: #0000ff; } 

DEMO: http://jsfiddle.net/AY3j6/

+3
source

Source: https://habr.com/ru/post/1479798/


All Articles