1
var elem2 = document.createElement("label");
elem2.setAttribute("value","something");
labelView.appendChild(elem2);
2
  • 4
    What is your question? What doesn't work? You are aware that this needs to be attached to the DOM to be visible? Commented Feb 16, 2011 at 9:27
  • 1
    You 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. Commented Feb 16, 2011 at 9:38

2 Answers 2

7

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);
Sign up to request clarification or add additional context in comments.

1 Comment

-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.
1

you have to add the element to the DOM via appendChild()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.