Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

input - jQuery change placeholder text color

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"});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...