How to change placeholder text with JavaScript?

Spread the love

To change placeholder text with JavaScript, we set the placeholder property.

For instance, we write

<input type="text" name="Email" placeholder="Some Text" />

to add an input.

Then we write

document.getElementsByName("Email")[0].placeholder = "new text for email";

to select the input with getElementsByName and get the first element from the returned node list.

And then we set the placeholder property to the new placeholder attribute value.

Leave a Reply

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