How i can insert dinamically something like "refer" inside my <> input tag, without writing it directly into html but using javascript? Something similar to
2 Answers
you can use setAttribute for this action
var i = document.querySelector("input");
i.setAttribute("name", "myinput");
ref: https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
Comments
Supposing you have this 👇
<input type="text" value="23" id="age"> </input>
You can select that element by
const ageInput = document.getElementById('age');
If what you want is to change the text inside you can do this by
ageInput.innerHTML = "Hello World"
Or you can set a new attribute by
ageInput.setAttribute("refer", "true");
setAttribute documentation 👉 https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute