View Full Version : Resolved Should be easy - Set element to show on page load

12-04-2008, 03:41 AM
Hi all,

Please forgive my silly question, I am a real beginner when it comes to anything Javascript based.

I have a div element that uses a JQUERY positioning script which works fine. However if Javascript is disabled by the user, the position of that div goes crazy.

To address this I have set "display:none" on the positioned div and am trying to work out how to use a javascript to then tell that div to have the style of block on load.

My reasoning behind this is that if the javascript is disabled, the div will stay hidden according to the css, if javascript is not disabled then the browser will detect the script which overrides the "display:none" css making it only visible to users with javascript enabled.

I hope this makes sense... Please remember I am a n00b when/if you reply to this post. ;)

PS: I have no problems with the fact that the div will be hidden from javascript=disabled users, it's just a visual thing and won't be missed by the rare few.

12-04-2008, 07:38 AM
Easiest way, put a small script in the head after the style that sets its display none. Say it's id is myDiv, so you could have something like -

What you have already:

<style type="text/css">
#myDiv {
display: none;

Then after that:

<script type="text/javascript">
document.write('<style type="text/css">#myDiv {display: block;}<\/style>');

12-04-2008, 09:04 PM
That's fantastic, thank you so much!