Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Page won't validate -- misuse of A element?

Reply
Thread Tools

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

 
 
Michael Laplante
Guest
Posts: n/a
 
      05-18-2006
(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


 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      05-18-2006
Michael Laplante <(E-Mail Removed)> 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?

 
Reply With Quote
 
 
 
 
Michael Laplante
Guest
Posts: n/a
 
      05-18-2006
"Jukka K. Korpela" <(E-Mail Removed)> wrote in message
news:JW2bg.1671$(E-Mail Removed)...
> Michael Laplante <(E-Mail Removed)> 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


 
Reply With Quote
 
Jonathan N. Little
Guest
Posts: n/a
 
      05-18-2006
In article <Dy2bg.22352$Qq.16523@clgrps12>, http://www.velocityreviews.com/forums/(E-Mail Removed)
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Misuse of XML namespaces; call for help in marshalling arguments Peter Flynn XML 2 08-09-2004 10:23 PM
Misuse of namespaces, help is summoning arguments Simon North XML 0 08-05-2004 11:52 AM
Employer misuse Marko Microsoft Certification 0 09-25-2003 06:09 AM
Re: Misuse of <tab> John Roth Python 8 08-12-2003 08:43 PM
Re: Hotmail and Computer Misuse anthonyberet Computer Support 39 08-11-2003 10:32 PM



Advertisments