1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>create Element</title> 5 </head> 6 <body> 7 <div id="testdiv"></div> 8 <script type="text/javascript"> 9 window.onload = function(){ 10 var para = document.createElement('p'); 11 var txt1 = document.createTextNode('This is ') 12 var em0 = document.createElement('em') 13 var txt2 = document.createTextNode('my') 14 var txt3 = document.createTextNode(' content') 15 var testdiv = document.getElementById('testdiv') 16 para.appendChild(txt1) 17 em0.appendChild(txt2) 18 para.appendChild(em0) 19 para.appendChild(txt3) 20 testdiv.appendChild(para) 21 } 22 </script> 23 </body> 24 </html>