How to use the <noscript> element "right"?
The HTML validator I found today - http://html5.validator.nu/ - says that my use of the <noscript> element is wrong. My XHTML source code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"> <body> <div id="head"> <noscript> <p>JavaScript is disabled.</p> </noscript> ... Error message from the reviewer:
Error: The noscript of the XHTML element is not resolved as a child of the XHTML div element in this context. (Suppression of further errors from this subtree.)
Contexts where a noscript element can be used:
- In the head element of an HTML document, if there are no ancestor noccript elements.
- In cases where phrasing is expressed in HTML documents, if there are no elements of noccript ancestors.
Content model for div element:
- Stream content.
Now I turned to the Mozilla documentation and tried to understand what this means. I found some information about content categories, stream content, phrasing content, about which elements belong to each category (regardless of what βbelongsβ means exactly) and how the <noscript> element can be used. ( https://developer.mozilla.org/en/HTML/Element/noscript )
Now I know this: <div> should contain the contents of the stream. <noscript> must be present in the content wording. This is clearly not consistent. How can i do this? However, many elements are represented both in the stream and in phrasing. They do not seem to be disjoint sets, so some cannot decide, or I do not understand.
How does the HTML specification intend to solve these quirks?
You should not use the HTML5 validator to validate your XHTML 1.1 document.
The HTML5 specification talks about the noscript element :
The
noscriptelement should not be used in XML documents.
So noscript inside a div not allowed in XHTML5, but it is allowed in XHTML 1.1.
You cannot use "noscript" in an XHTML / XML document because it disables the parser for the contents of "noscript", and you cannot do this in XML. The parser cannot be temporarily disabled or disabled.
For example, the CSE HTML Validator generates this message for XHTML documents: XHTML documents should not use the "noscript" element. This is because noscript works by turning off the parser when the scripts are on, which is not possible in XML. In addition, the noscript element is not explicitly allowed in HTML5 for this reason.
If you want to use "noscript" correctly, you will need to change the document type to HTML5 (recommended) or HTML4 instead of XHTML.
Use the official validator to validate your HTML. The following code works fine for me:
<!DOCTYPE html> <html> <head> <title>I AM YOUR DOCUMENT TITLE REPLACE ME</title> </head> <body> <div id="head"> <noscript> <p>JavaScript is disabled.</p> </noscript> </div> </body> </html> EDIT: Interestingly, the W3C validator claims that the parser is based on the validator at the link you provided.
'The downloaded document was successfully validated as HTML5. This means that the resource in question has identified itself as "HTML5" and that we have successfully completed its official review. The parser implementations we used for this check are based on validator.nu (HTML5). ''
Perhaps the validator in http://validator.nu is an older version. Edit Editing: No, this also checks well. Validated as HTML5 and XHTML 1.0 Strict.