how to create label element in javascript
var elem2 = d开发者_StackOverflowocument.createElement("label");
elem2.setAttribute("value","something");
labelView.appendChild(elem2);
Did you add it to the DOM?
Also, a <label>
element doesn't make use of the value
attribute, it uses innerHTML
.
var elem2 = document.createElement('label');
elem2.innerHTML = "something";
document.getElementsByTagName('body')[0].appendChild(elem2);
you have to add the element to the DOM via appendChild()
精彩评论