Get div tag height

I have a div tag, in this div tag I am writing results from a database (with PHP / MYSQL). I want the title height of this div tag. The problem is that sometimes a warning returns an incorrect div height (less than the actual result). sometimes the result is correct.

I think this happens because javascript returns the result earlier than php finishes its work and on this the result is less than the real div tag. Does anyone know how to solve this problem? (apropos, incorrect warning result, only chrome and safari, in opera and firefox the result is always real.) this is php code:

$res = mysqli_query("SELECT some_column FROM table");
echo '<div id="my_div">';
while ($row = mysqli_fetch_row($res)) {
    echo '<p>'.row[0].'</p>';
}
echo "</div>";

and js code:

$(document).ready ( function () {

   alert( $("#my_div").height() );

});
+5
source share
2 answers

calculate the height after loading the page,

window.onload = function (){
    alert( $("#my_div").height() );
}
+3
source

All Articles