Results 1 to 10 of 10

Thread: Setting Styles in JS...

  1. #1
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default Setting Styles in JS...

    I've been Googling to try and find how you set styles with js but I just can't find it. I'm trying to set the visibility of the document. I tried document.styles.visibility = hidden;
    and I tried
    document.styles.setProperty("visibility","hidden");
    but nether worked.

    How do you?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Set styles on what?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Sorry I didn't say. I meant the entire document. Also, is there any way to override other styles without doing it element by element?

  4. #4
    Join Date
    Feb 2007
    Posts
    293
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Why would you want to hide an entire document?

  5. #5
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Try this (not tested):
    Code:
    var styleHideAll = document.createElement("style");
    styleHideAll.appendChild(document.createTextNode("*{visibility:hidden!important;}"));
    document.head.appendChild(styleHideAll);
    
    document.onload = function() {document.head.removeChild(styleHideAll);}

  6. #6
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    For a loader thing. It hides the entire document and says loading untill it finishes loading and then shows it. But it would be cool if you could find loading progress for a loading bar, but whatever.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Well...
    Code:
    document.body.style.display = "none";
    onload = function() {
      document.body.style.display = "";
    };
    For a loading message, you can just set the style of the containing element in the same way. An actual loading bar indicating how far it's loaded would be trickier.

    However, this isn't too clever. You don't really want to disable progressive loading: it might confuse your users, and even if it doesn't, psychologically speaking, users will think the page loads more slowly if they can't see it happening. It's also less efficient -- with progressive loading, users can begin reading the content before all the images have downloaded, for example.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Thanks, I was using document.getElementsByTagName("body")[0] to get the body, so it wasn't working.

  9. #9
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Wait, when I tried it in Firefox it said:

    Error: document.body has no properties
    Source File: file:///C:/Documents%20and%20Settings/Stephen/Desktop/Crap/js%20classes/loader.htm
    Line: 4
    So, um, did I mess up? My page is:

    <html>
    <head>
    <script type="text/javascript">
    document.body.style.display = "none";
    onload = function() {
    document.body.style.display = "";
    };
    </script>
    </head>
    <body> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa </body>
    </html>

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's because you placed it in the <head>. The <body> hasn't been loaded yet. If you place it in the <body>, it should work.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •