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

M

Michael Laplante

(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
 
J

Jukka K. Korpela

Michael Laplante said:
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 said:
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
(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?
 
M

Michael Laplante

Jukka K. Korpela said:
Michael Laplante <[email protected]> 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
 
J

Jonathan N. Little

(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
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">...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top