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"});
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"});
Just add this. It will inherit the color in input[type=text]:focus new color
If you don't have a stylesheet, and want to inject CSS dynamically you can use the following:
Just use my_class and the color for the placeholder.
It's handy to have a general purpose function:
Usage:
You can't really modify pseudo-selectors with JavaScript. You'll have to modify an existing a
<style>
element.If possible, make a class:
And add it to the element:
I was using MaterializeCSS; I used Jquery to update CSS for input fields like this
See Result:
https://codepen.io/hiteshsahu/pen/EXoPRq?editors=1000
Here is an example of dynamically setting pseudo-element styles using jQuery – it's a matter of creating a
<style>
element, setting its text content to the desired style declarations, and appending it to the document.Here is a simple single-page example: