jQuery change placeholder text color

Benny picture Benny · Feb 19, 2013 · Viewed 47k times · Source

Is it possible to use "::-webkit-input-placeholder" with jQuery to set a color for the placeholder text?

Something like this:

$("input::-webkit-input-placeholder").css({"color" : "#b2cde0"});

Answer

Blender picture Blender · Feb 19, 2013

You can't really modify pseudo-selectors with JavaScript. You'll have to modify an existing a <style> element.

If possible, make a class:

.your-class::-webkit-input-placeholder {
    color: #b2cde0
}

And add it to the element:

 $('input').addClass('your-class');