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.