I thought the following script will create div element but I got nothing output in my html. Could anyone help me out? Thanks a lot.
var div=document.createElement('div');
div.setAttribute('id','testttttttt');
div.innerHTML='fjsoidfjiosdjfoi';
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have to use the
appendChildmethod in the end:Otherwise, the created element will exist, but won’t appear in your page.
Also, you have to be sure that
document.bodyexists, otherwise, it will throw an error (if this script is going to be executed when loaded, put it inside anonloadevent).PS: You can also append to any other DOM elements:
JSFiddle example: http://jsfiddle.net/AkXTr/