Categories
JavaScript Answers

How to change placeholder text with JavaScript?

Spread the love

Sometimes, we want to change placeholder text with JavaScript.

In this article, we’ll look at how to change placeholder text with JavaScript.

How to change placeholder text with JavaScript?

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

For instance, we write

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

to select the input with getElementsByName.

Then we get the first element with [0].

And then we set the placeholder property to the placeholder text we want to show.

Conclusion

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

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.