How to change the placeholder text using jquery

This article was written by in February 3, 2015, & may not be posted on other sites!
Original source url for this article: How to change the placeholder text using jquery

How to change the placeholder text using jquery.
This is how to alter form field placeholder text or actual text in form fields using jQuery.

How to change the placeholder text using jquery & alter form text input

 

How to change the placeholder text jQuery

Placeholder text is like help text telling the user what to write in a field. Here are different examples on how to change or alter the placeholder text using jQuery. Make sure you have jQuery enabled on your website before starting. Replace the class .your-subject to match your form field class.

To alter the placeholder text in a single text field, use this jquery code:
$(".your-subject input").attr("placeholder", "my placeholder text").val("").focus().blur();

If you have multiple fields and want to have the same placeholder text in all of them,
use this jquery code:
$('form').find("input[type=textarea], input[type=password], textarea").each(function(ev){
if(!$(this).val()) {
$(this).attr("placeholder", "Type your answer here");
}
});

 

If you want to put actual text inside a text field using jQuery

Placeholder text is more like help text. To put actual text inside a text field, for example as a dynamic subject, use this code:
$(".your-subject input").val("My text");

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *