Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript width of div, returns 0

Tags:

javascript

css

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

#areaDraw {
margin-top:50px;
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);
}).listener();

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

so whats wrong with:

document.getElementById("areaDraw").style.width
like image 442
Em Sta Avatar asked Jul 17 '13 12:07

Em Sta


1 Answers

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

like image 68
Patsy Issa Avatar answered Oct 04 '22 08:10

Patsy Issa