Ugh. Don't use inline scripts where you avoid them, and don't use innerHTML when direct DOM creation and insertion is available. And use CSS to handle the positionin/spacin aspect. Images already display inline, so wrapping divs around them individually is just complicating things.
Without knowing what your method does, I'm guessing, but this is what you should be doing roughly:
<head>
<script>
function createImage(t,params)
{
var img = document.createElement('img');
/* season img to taste (e.g. img.src = params.source? */
t.appendChild(img);
}
/* bind this method to onload event or better a ready event */
function exec()
{
var t = document.getElementByid('target');
createImage(t,xx);
createImage(t,yy);
createImage(t,zz);
}
</script>
<style>
/* I'm not advocating px here and these are just example values */
#target {width: 600px; text-align: center;}
#target img {border: 0px; margin: 0 10px; } /* the margin handles the spacing */
</style>
</head>
<body>
<div id="target"></div>
</body>
JS DOM methods reference
Why is innerHTML bad? Whilst it's true it can be faster, it's not always true, and it's close anyway, but then speed isn't really the problem with JS. However innerHTML:
- opens up an injection attack
- can create memory leaks when it destroys pre-existing elements with event handlers
- being string based is error prone
- doesn't return a reference to what you just inserted, and can't clone