开发者

how to create label element in javascript

开发者 https://www.devze.com 2023-02-11 13:34 出处:网络
var elem2 = d开发者_StackOverflowocument.createElement(\"label\"); elem2.setAttribute(\"value\",\"something\");
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()

0

精彩评论

暂无评论...
验证码 换一张
取 消