How to change the color of placeholder when focus the input field? I use this CSS code to set the default color, but how to change it on focus?
::placeholder { color: blue; }
<input type="text" placeholder="A red placeholder text..">
$('input'). focus(function() { $(this). attr('placeholder', 'enter your email address...') }).
Note: In most browsers, the appearance of placeholder text is a translucent or light gray color by default.
Use the ::placeholder pseudo-element to style your placeholder text in an <input> or <textarea> form element. Most modern browsers support this, but for older browsers, vendor prefixes will be required.
Try this, this should work :
input::-webkit-input-placeholder {
color: #999;
}
input:focus::-webkit-input-placeholder {
color: red;
}
/* Firefox < 19 */
input:-moz-placeholder {
color: #999;
}
input:focus:-moz-placeholder {
color: red;
}
/* Firefox > 19 */
input::-moz-placeholder {
color: #999;
}
input:focus::-moz-placeholder {
color: red;
}
/* Internet Explorer 10 */
input:-ms-input-placeholder {
color: #999;
}
input:focus:-ms-input-placeholder {
color: red;
}
Here is an example : http://jsfiddle.net/XDutj/27/
This works for me:
input:focus::placeholder {
color: blue;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With