Forum Moderators: open
I'm having a hard time getting the following code to validate.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
</head>
<body>
<div><script type="text/javascript"></script><noscript><a href="http://www.test.com/">Test</a></noscript></div>
</body>
</html>
This is the line that gives me the problems:
<div><script type="text/javascript"></script><noscript><a href="http://www.test.com/">Test</a></noscript></div>
The W3 Validator says that the anchor tag is not allowed there because it's missing a starting tag, like a p, div, or header tag. But the thing is, it is in one, right there at the beginning of the line!
It validates fine if the noscript tag is removed, which makes me wonder, does the noscript cancel out the div? Is the only way I can solve this is to add an extra div tag inside the noscript? Or is my code fine, and it's just a bug in the validator?
Thanks
does the noscript cancel out the div?
Sorta - yeah. HTML Strict - which is the doctype you're using - is very strict about the order in which you place things. So yes, if you put an extra <div> tag in there, or <p> tag it'll work for you.
You've got 2 options: change your doctype to:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
or add in an extra tag, like <pre>, right before your <a> tag.
HTH!
I definitely want to try to strive towards the higher 4.01 Strict threshold.
So therefore, I need to put the paragraph into a container.
I'll go ahead and place a div tag inside the noscript.
I guess this brings up a new concern in CSS, since the first <div> has a special style, would I have to repeat the same style for the second <div> since the first <div> was "cancelled"?
I'm just thinking out-loud. I'll have to run some tests, and this new sub-question would probably be better suited in the CSS forum. It just seems like it can start me down a path of browser compatibility hell.
Lame.