Em Sta Em Sta - 1 year ago 76
CSS Question

Javascript width of div, returns 0

I m trying to retrieve the width of an div for my function with javascript:

#areaDraw {
width: 50%;
min-height: 100%;
z-index: 1000;

and the function:

Event.add(window, "resize", function() {
sketch.resize(document.getElementById("areaDraw").style.width, window.innerHeight);

somehow javscript always returns 0 for the width of the div(areaDraw)

so whats wrong with:


Answer Source

Try document.getElementById("mydiv").offsetWidth instead of .style.width

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download