I have a jQuery script that reads img height and adds style tag to head tag.
jQuery
var img = document.getElementById('logomini');
height = img.clientHeight;
$(function (){
$("<style type='text/css' id='style1'>#menu ul { line-height: "+ height +"px }</style>").appendTo("head");
});
The problem: sometimes the script is working properly and sometimes it's not. When I'm refreshing my website (Wordpress) the line-height is 80px or 0px. I think it's a problem with script loading. When script is loading faster than img it showing 0px. But it's only my guess... The script tag is right before </body>
tag.
Any ideas?