notacountry
notacountry

Reputation: 65

Setting a button's text through script

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!

Upvotes: 0

Views: 70

Answers (1)

Kyle
Kyle

Reputation: 1503

Missing closing parenthesis:

.appendChild( ... )

var container = document.getElementById("container");

var button = container.appendChild(document.createElement("button"));

button.innerHTML="Click Me!!";
<div id="container"></div>

Upvotes: 1

Related Questions