HTML for loop inside ul element, insert <option> element to UL - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

HTML for loop inside ul element, insert <option> element to UL

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w  w  w .  j  ava2  s. c o m*/
(function() {
  var list = document.getElementById('dynamicList');
  for (var i = 0; i < 5; i++) {
    var li = document.createElement('li');
    li.innerHTML = i;
    list.appendChild(li);
  }
})();
    }

      </script> 
   </head> 
   <body> 
      <h1>Dynamic List Example</h1> 
      <ul id="dynamicList"></ul>  
   </body>
</html>

Related Tutorials