I want to set the placeholder
value to an input
I am creating dynamically with javascript. How can I do that on creation ?
var input = document.createElement('input');
input.className = 'my-input-class';
input.placeholder ???
I want to set the placeholder
value to an input
I am creating dynamically with javascript. How can I do that on creation ?
var input = document.createElement('input');
input.className = 'my-input-class';
input.placeholder ???
var Yourinput = document.createElement('input');
Yourinput.className = 'my-input-class';
Yourinput.placeholder = "Some text";
You can set it this way.
You can use the setAttribute
method on the input:
input.setAttribute('placeholder', 'Some Awesome Text');
or, since .placeholder
has a getter and a setter on it, you can do this:
input.placeholder = 'Some Awesome Text';
input.placeholder = "your_value"
works for standard attributes otherwise use setAttribute
.
See here