SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Feb 2014
    Location
    Warragul, Australia
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    top of page code

    Hello,
    In a previous closed thread (http://www.sitepoint.com/forums/show...age-navigation), I would like to know the correct place to enter <body id="top">. The code works perfectly but validation says 'The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed). ' I placed this part of the code before <style type="text/css">. TIA

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,826
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    It is telling you the error - you have a style tag in the body where they all must go in the head.

    Code:
    <html>
    <head>
    <title></title>
    <style></style>
    </head>
    <body>
    
    </body>
    </html>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Feb 2014
    Location
    Warragul, Australia
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I'm confused. Please look at http://members.dcsi.net.au/vivienrk/p2.html.
    Where is the correct place for the code on line 105 please?

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,826
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Your page has two body tags - one at the top of the body and one part way down on line 105.

    Get rid of the second body tag and put the id either on the first body tag or on whichever other tag is at the location where you want the id.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Member
    Join Date
    Feb 2014
    Location
    Warragul, Australia
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Done that (I think) but I still get an error -
    Line 23, Column 15: document type does not allow element "body" here

    <body id="top">

    The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,826
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Your body statement on line 72 is in the correct location.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Member
    Join Date
    Feb 2014
    Location
    Warragul, Australia
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Stephen - it validates now. Maybe I didn't refresh or something but many many thanks for persevering!!

  8. #8

    Join Date
    Apr 2014
    Location
    HO CHI MINH VIET NAM
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Normal, i do not get id for my body and only have one of tag body. Wish greate for you.

  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,185
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    Yes, I can't see a reason for giving it an id.
    id-s are supposed to be unique so that the element can be easily distinguished from others.
    As body is already unique (or at least it should be) you can simply target it by "body".
    Easy for CSS and some little differences with javascript, but no need to give it an id that I can think of.

  10. #10
    SitePoint Member
    Join Date
    Feb 2014
    Location
    Warragul, Australia
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mitt and Nguyen. So what is the code to send the viewer to the top of the page and where do I place it. Thanks.

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,185
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    AutisticCuckoo's way would be similar to how I would do it. http://www.sitepoint.com/forums/show...=1#post3317110
    The "top" element inside body (the body's first child node) might not be an H1 tag, and if it already had an id I would use that instead of "top", but that's how I'd do it.

  12. #12
    SitePoint Member
    Join Date
    Feb 2014
    Location
    Warragul, Australia
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks heaps Mitt!!! That passed the validation and I feel better now that I can just write <body>.

  13. #13
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by mitt
    Easy for CSS and some little differences with javascript, but no need to give it an id that I can think of.
    True, though I tend to do such now and then for Back To Top widgets, where I may not know for certain that every page begins with the same first child inside the body.. so an id on the body as a link target destination is the lazy/easy way :)


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
  •