I have an input field with a span placeholder inside of it. What I’d like to do is change the color of the placeholder when the input field is clicked. Here is a jsFiddle with an example of my field.
What’s the best way to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use a selector for the input element and then grab the previous span. Add a class that affects the color. On blur remove the class.
http://jsfiddle.net/Vbnj2/1/
Modern browsers have added support for the
placeholderattribute. You just addplaceholder="My Text"as an input attribute and the browser will automatically insert/remove it as necessary.