Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts

    style,script{display:block;} ??

    Do the browsers use display property to hide these tags?

    Has anyone tried a CSS like
    Code:
    style,script{
    display:block;
    }
    ?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You can only style the content of the <body> of the page.

    style and script tags belong in the <head> of the page and therefore can't be styled.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,917
    Thanks
    6
    Thanked 1,040 Times in 1,013 Posts
    Quote Originally Posted by felgall View Post
    style and script tags belong in the <head> of the page and therefore can't be styled.
    Well, not quite. You can put a script anywhere in the document. Try styling that and you’ll see what happens.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Exactly, we don't have an option to edit javascript in firebug. Using this technique we can do some tricks (say some alerts for testing) on run just like editing html.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by VIPStephan View Post
    Well, not quite. You can put a script anywhere in the document. Try styling that and you’ll see what happens.
    I didn't say that you can't put a script in the body of the page - just that scripts belong in the head of the page because you shouldn't be polluting the body content with something which is not a displayable element.

    With the exception of the document.write command (which should not be used anyway) it shouldn't make any difference whether a script is in the head or body of the page except with regard to timing issues as to when you want it to run. While some people place their script immediately before the </body> in order for it to not have to wait for all the images to load as would be the case if they put it in the head and triggered it with window.onload, that location is really no different from having it in the head of the page in so far as what it outputs to the web page is concerned. All outputs to the page from JavaScript should be done using either the appropriate DOM commands or innerHTML and it is the elements created from those commands that need to be styled and not the <script> tag.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    I disagree. I find it very useful to place scripts in my body tag for DOM reasons. Aka, document.getElementById().

    Yes, I could send a callback to document.addEventListener("load", callback, false), but sometimes doing stuff like that is a bit overkill and silly, like when your whole code would have to be put into a callback.
    Trinithis

  • #7
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    There are legitimate reasons to place script blocks inside the body tag

    There are legitimate reasons to place script blocks inside the body tag. Some of them were already mentioned. An additional one is that if you place your script tags at the bottom of the document, the page will appear to load faster. When the script tags are in the head, all the JS must be loaded and parsed before the browser continues on to render the displayable elements.

  • #8
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    I recall seeing experiments where the author set head, style { display: block }, and in some browsers, that would work.

  • #9
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Anyway, to answer the original question: IIRC it works. Sort of. In some browsers (and a bit differently depending on which browser...). The head element has display: none; as well, though, so you need to deal with that. But I might be mistaken, that these are hard coded. I know for sure, though, that I have had pretty much the entire document tree render in at least Opera, including children of the head element.

    Felgall: There's nothing about the head element that makes it a special non-rendering container - it has meta-information semantics, but that's got nothing to do with it's presentation. Those semantics are why it defaults to not render, though. Whether the non-rendering is hard coded (I believe it is in IE) or through user-agent default style sheet is another question. However, it's just an element in the node tree. CSS operates on the entire node tree. So CSS can govern also the rendering or non-rendering of the head element and descendants in theory.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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