Results 1 to 3 of 3

Thread: Should be easy - Set element to show on page load

  1. #1
    Join Date
    Mar 2008
    Posts
    34
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default Should be easy - Set element to show on page load

    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.
    Last edited by mobius2000; 12-04-2008 at 09:04 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:
    Code:
    <style type="text/css">
    #myDiv {
    display: none;
    }
    </style>
    Then after that:
    Code:
    <script type="text/javascript">
    document.write('<style type="text/css">#myDiv {display: block;}<\/style>');
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    mobius2000 (12-04-2008)

  4. #3
    Join Date
    Mar 2008
    Posts
    34
    Thanks
    7
    Thanked 1 Time in 1 Post

    Default

    That's fantastic, thank you so much!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •