Page won't validate -- misuse of A element?

Discussion in 'HTML' started by Michael Laplante, May 18, 2006.

  1. (Sound of grinding teeth. . .)
    I've solved my previous hyperlink issue in IE with the following:

    <body>
    <a name="top" id="top">&nbsp;</a>

    -- page content --

    <div style="text-align: center">
    <a href="#top">Back to top</a>
    </div>

    I've set the doc type to HTML4.01 strict. When I go to validate it though I
    get this:

    ***
    Below are the results of attempting to parse this document with an SGML
    parser.

    1.. Error Line 11 column 26: document type does not allow element "A"
    here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV",
    "ADDRESS" start-tag.
    <a name="top" id="top">&nbsp;</a>The mentioned element is not allowed to
    appear in the context in which you've placed it; the other mentioned
    elements are the only ones that are both allowed there and can contain the
    element mentioned. This might mean that you need a containing element, or
    possibly that you've forgotten to close a previous element.

    One possible cause for this message is that you have attempted to put a
    block-level element (such as "<p>" or "<table>") inside an inline element
    (such as "<a>", "<span>", or "<font>").

    ***

    Why is <a> not allowed here? It's the first bit of code after <body> and
    there is no block-level element contained within it, so what's the issue
    here? Must it be enclosed in a <P> or other block level element to validate?
    (I'm about to go off and do this but nothing on the w3 reference suggests
    this is a necessity.)

    FWIW, the WDG validator gave me a similar message.



    M
    Michael Laplante, May 18, 2006
    #1
    1. Advertising

  2. Michael Laplante <> scripsit:

    > I've solved my previous hyperlink issue in IE with the following:
    >
    > <body>
    > <a name="top" id="top">&nbsp;</a>


    Which issue? There is no problem here before you decide to create one.
    First, "Back to top" links are not needed - they are in fact harmful, see
    http://www.cs.tut.fi/~jkorpela/www/totop.html
    Besides, even if users needed such links, you could set them up using just
    href="#", without artificial constructs.

    > I've set the doc type to HTML4.01 strict.


    Do you know what that means?

    > <a name="top" id="top">&nbsp;</a>The mentioned element is not
    > allowed to appear in the context in which you've placed it;


    Isn't this rather obvious? The <a> element is allowed where it is. Now just
    check the HTML 4.01 Strict syntax. It does not allow <a> elements directly
    insider <body>.

    > Why is <a> not allowed here? It's the first bit of code after <body> and
    > there is no block-level element contained within it, so what's
    > the issue here?


    It's not _contained in_ a block-level element?

    > Must it be enclosed in a <P> or other block level
    > element to validate?


    Bingo. But it's not a paragraph, so <p> would be semantically wrong. So
    <div> would fix the syntactic issue. So would removing the useless <a>
    element.

    > (I'm about to go off and do this but nothing on
    > the w3 reference suggests this is a necessity.)


    Really? Not even the HTML 4.01 specification?
    Jukka K. Korpela, May 18, 2006
    #2
    1. Advertising

  3. "Jukka K. Korpela" <> wrote in message
    news:JW2bg.1671$...
    > Michael Laplante <> scripsit:
    >
    > Which issue? There is no problem here before you decide to create one.
    > First, "Back to top" links are not needed - they are in fact harmful, see
    > http://www.cs.tut.fi/~jkorpela/www/totop.html


    Some good points there. However, in my experience, the vast majority of
    internet users are unaware of keyboard shortcuts. But I like your "Back to
    top link" example. . . will likely use that, if ok with you.

    > Bingo. But it's not a paragraph, so <p> would be semantically wrong. So
    > <div> would fix the syntactic issue. So would removing the useless <a>
    > element.


    See above.

    Thx for the input.

    M
    Michael Laplante, May 18, 2006
    #3
  4. In article <Dy2bg.22352$Qq.16523@clgrps12>,
    says...
    > (Sound of grinding teeth. . .)
    > I've solved my previous hyperlink issue in IE with the following:
    >
    > <body>
    > <a name="top" id="top">&nbsp;</a>
    >
    > -- page content --
    >
    > <div style="text-align: center">
    > <a href="#top">Back to top</a>
    > </div>
    >
    > I've set the doc type to HTML4.01 strict. When I go to validate it though I
    > get this:
    >
    > ***
    > Below are the results of attempting to parse this document with an SGML
    > parser.
    >
    > 1.. Error Line 11 column 26: document type does not allow element "A"
    > here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV",
    > "ADDRESS" start-tag.
    > <a name="top" id="top">&nbsp;</a>The mentioned element is not allowed to

    <snip>
    > Why is <a> not allowed here? It's the first bit of code after <body> and
    > there is no block-level element contained within it, so what's the issue
    > here? Must it be enclosed in a <P> or other block level element to validate?
    > (I'm about to go off and do this but nothing on the w3 reference suggests
    > this is a necessity.)
    >
    > FWIW, the WDG validator gave me a similar message.


    You need to learn how to read the error message. Look at the spec for the
    BODY element

    http://www.w3.org/TR/html4/struct/global.html#edef-BODY

    <!ELEMENT BODY O O (%block;|SCRIPT)+ +(INS|DEL) -- document body -->
    ^^^^^^^^^^^^^^^
    This tells what elements can follows (immediate child) the BODY opening
    tag.

    a block element or the SCRIPT element and that is all. A element is NOT a
    block but an inline-element so therefore the error message lists for you
    what element opening tag must precede the A element after the BODY.

    <body><some_block_element_tag><a name="something">...

    --

    Jonathan
    Jonathan N. Little, May 18, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon North
    Replies:
    0
    Views:
    350
    Simon North
    Aug 5, 2004
  2. Peter Flynn
    Replies:
    2
    Views:
    419
    Peter Flynn
    Aug 9, 2004
  3. John Roth

    Re: Misuse of <tab>

    John Roth, Jul 30, 2003, in forum: Python
    Replies:
    8
    Views:
    356
    Robin Munn
    Aug 12, 2003
  4. Michael Sampson

    Re: Misuse of <tab>

    Michael Sampson, Jul 30, 2003, in forum: Python
    Replies:
    5
    Views:
    354
    Ben Finney
    Jul 31, 2003
  5. naive misuse?

    , Aug 28, 2006, in forum: Python
    Replies:
    3
    Views:
    333
    Simon Forman
    Aug 29, 2006
Loading...

Share This Page