title: Creating dynamic div using javascript
body: <pre><code> &lt;script&gt;
      function selecteditems()
      {
  
      var i=1;
      var val="";
      while(i&lt;=53)
      {
  
          if(document.getElementById('timedrpact'+i)!="")
          {
              val+=document.getElementById('timedrpact'+i).value;
              document.getElementById('showselecteditems').innerHTML=val;
              }
          i++;
          }
  
      }
      &lt;/script&gt;
  </code></pre>
  
  <p>How to create a new div and add contents to it?In the above case i lost previous content due to innerHTML.I want new div each time for dynamically attach an image and the above variable val to it.
  <img src="https://i.stack.imgur.com/haGFO.jpg" alt="The desired and current output demonstrated here"></p>
  
  <p>Thanks in advance.</p>