user2639637
user2639637

Reputation:

Changing the color of the input value? jQuery

I want to change the text color inside the input field. Color of those input words that are input by the users & color the default color.

Here's the jQuery Code:

var default_email_val = 'Enter Your E-Mail';

$(document).ready(function(){
    $('input[type="email"]').attr('value', default_email_val).focus(function(){
        if($(this).val()==default_email_val){
            $(this).attr('value', '');
        }
    }).blur(function(){
        if($(this).val()== ''){
            $(this).attr('value', default_email_val);
        }
    });
});

I want to change the color, of the text field to grey when the page loads & when the user input some words, I want to keep those words with a black color, Using CSS or any other method.

How can I do that?

Upvotes: 0

Views: 175

Answers (2)

ProllyGeek
ProllyGeek

Reputation: 15866

consider using jquery method .css()

$(this).css("background-color","#cccccc");

Upvotes: 0

Raul Rene
Raul Rene

Reputation: 10280

As far as I can tell from the provided jQuery you want a placeholder functionality. This already exists in HTML5.

Just create an input with the placeholder attribute:

<input placeholder="Enter your E-mail" type="text">

See here more on the placeholder attribute

Upvotes: 1

Related Questions