How to change placeholder text with JavaScript?

Estimated read time 1 min read

You can change the placeholder text of an HTML element in JavaScript by using the placeholder property. To set the placeholder text, you can assign a string value to the placeholder property.

Here’s an example:

const input = document.querySelector('input');

input.placeholder = 'Enter some text';

In this example, we select an input element and change its placeholder property to a string value 'Enter some text'. The new placeholder text will be displayed in the input element until a user enters some text or the placeholder property is changed again.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply