This question already has an answer here:
I am setting up a button via javascript, but the button shows not the text.
Any recommendation on how to fix it?
var b = document.createElement('button');
b.setAttribute('content', 'test content');
b.setAttribute('class', 'btn');
b.value = 'test value';
var wrapper = document.getElementById(divWrapper);
wrapper.appendChild(b);
Thanks!
The value of a button element isn't the displayed text, contrary to what happens to
input
elements of type button.You can do this :
Demonstration
Basically, use innerHTML instead of value, because the 'button' type you are appending sets it's value in its innerHTML.
JS:
Looks like this in the DOM:
Demo: http://jsfiddle.net/CuXHm/
Set the text of the button by setting the innerHTML
http://jsfiddle.net/jUVpE/
Create a text node and append it to the button element: