This is a bit of a gotcha for young players in the Javascript game. You have a web page with a DIV which you fill dynamically with, let’s say, 5 IMG elements. How do you get the width of the DIV? You can try

document.getElementById('divId').width

but it will do you no good. The answer, use

document.getElementById('divId').offsetWidth

Here’s a handy guide when it comes to DHTML element position and locations.