Hallo zusammen,
im Kopf habe ich den Dokumententyp wie folgt definiert:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Im HTML Code habe die Stelle:
<script type="text/javascript">
document.write ("<div id='pict' style='padding:5px'>Test</div>");
</script>
Der Validator meckert:
"The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed)."
Ich habe nun folgende Variante probiert:
<script type="text/javascript">
document.write ("<div id='pict' style='padding:5px'>Test</div>");
</script>
zusätzliches Backslash beim schliessenden DIV Attribut.
Was mich vollkommenden überrascht. Wenn ich die Hochkommas mit " maskiere meckert der Validator noch mehr.
<script type="text/javascript">
document.write ("<div id="pict" style="padding:5px">Test</div>");
</script>
You have used a character that is not considered a "name character" in an attribute value. Which characters are considered "name characters" varies between the different document types, but a good rule of thumb is that unless the value contains only lower or upper case letters in the range a-z you must put quotation marks around the value. In fact, unless you have extreme file size requirements it is a very very good idea to always put quote marks around your attribute values. It is never wrong to do so, and very often it is absolutely necessary.
Weiss jemand Rat?
Danke im voraus, Stefan