<script>
function selecteditems()
{
var i=1;
var val="";
while(i<=53)
{
if(document.getElementById('timedrpact'+i)!="")
{
val+=document.getElementById('timedrpact'+i).value;
document.getElementById('showselecteditems').innerHTML=val;
}
i++;
}
}
</script>
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.
Thanks in advance.
Check this Demo
Syntax for dynamic create div:
Look at
document.createElement()
andelement.appendChild()
.Because you will likely encounter this in the near future: You can remove any
element
with this code:Using createElement:
Full version using cloneNode (faster) and eventBubbling
Live Demo