This happens because document.write
would overwrite your existing code therefore place your div
before your javascript code. e.g.:
CSS:
#mydiv {
visibility:hidden;
}
Inside your html file
<div id="mydiv">
<p>Hello world</p>
</div>
<script type="text/javascript">
document.getElementById('mydiv').style.visibility='visible';
</script>
Hope this was helpful