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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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