var elem2 = document.createElement("label");
elem2.setAttribute("value","something");
labelView.appendChild(elem2);
-
4What is your question? What doesn't work? You are aware that this needs to be attached to the DOM to be visible?Pekka– Pekka2011-02-16 09:27:18 +00:00Commented Feb 16, 2011 at 9:27
-
1You should use something like "Webdeveloper toolbar" for firefox to inspect the generated source. So you can see what happens and fix little mistakes like these.pdu– pdu2011-02-16 09:38:41 +00:00Commented Feb 16, 2011 at 9:38
Add a comment
|
2 Answers
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);
1 Comment
Rafe
-1 for trying to indicate a label should use innerHTML. And for leaving out the most important part of a label which is the 'for' to associate it with a form element.