Prashobh
Prashobh

Reputation: 9544

How to give placeholder color?

Hi below text is a placeholder that is from js ,its color is #ccc .I need the textarea color as black ,right now it is taking placeholder color .

<textarea id="txt1" class="txt1 required" name="comment1"></textarea><br>


 var firstname = userModel.get('firstName');
  $('textarea#txt1').val('Hey ' +firstname+',\nTell us what is on your mind').css('color','#ccc');
    });

How to give different color for textarea and placehoder

Upvotes: 0

Views: 1236

Answers (3)

Talha Ahmed Khan
Talha Ahmed Khan

Reputation: 15473

basically you are defining a color to the textarea. so it will be equal for all the text.

If you are using HTML 5 then we can write the textarea as follows.

<textarea id="txt1" 
    placeholder='Hey, Tell us what is on your mind' 
    class="txt1 required" name="comment1"></textarea>

But if you are not using HTML5, Then we can use a very good jQuery plugin (I personally used it)

https://github.com/mathiasbynens/jquery-placeholder

EDIT

Want to add the name in placeholder.

var firstname = userModel.get('firstName');
$('textarea#txt1').attr('placeholder','Hey '+firstname+', Tell us what is on your mind');

Upvotes: 0

Beno
Beno

Reputation: 4753

The placeholder text can be set using the placeholder attribute like so:

var name = "some name";

$('#txt1').attr('placeholder', 'Hey ' + name + ', Tell us what is on your mind'); 

http://jsfiddle.net/rxhHS/1/

Upvotes: 4

Sibu
Sibu

Reputation: 4617

Using CSS

   .txt1{background-color:black;color:white;}
    #txt1::-webkit-input-placeholder {
      color: #ccc;
    }

DEMO

Upvotes: 0

Related Questions