Append text to div using ID in javascript - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Append text to div using ID in javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <div id="mylist"></div> 
      <script type="text/javascript">
 function coucity(){/*from  w w  w  .  ja  v  a  2 s . c  o  m*/
   for (var i = 0; i < 10; i++) {
     printList(i);
    }
 }
 function printList(city){
  var writecity = document.createTextNode(city);
  document.getElementById("mylist").appendChild(writecity);
 }
coucity();

      </script>  
   </body>
</html>

Related Tutorials