I have a button in my html that I append. How do I set said button's text to "Click Me"? I've scoured every corner of Stack Overflow and to no avail.
var button = container.appendChild(document.createElement("button");
button.setAttribute("id", button);
Here's what I've already tried:
button.text="Click Me"
button.innerHTML="Click Me";
button.value="Click Me";
button.childNodes[0].nodeValue="Click Me";
Any help will be appreciated!
innerHTMLorinnerTextshould have worked.button.setAttribute("id", button);probably doesn't do what you expect. Maybe you should wrapbuttonin the argument list into quotes. Currently the id is[object HTMLButtonElement].)on thevar button =line, so the button isn't created. After fixing the typo, it works withbutton.innerHTML. See jsfiddle.net/barmar/qsk8ahej/1