Bitte um kleine javascript Hilfe

Ronald Nickel

Legendäres Mitglied
Hallo an der JS-Front
de W3C HTML Validator meckert mit in eine js-script folgenden Part an:
<script type="text/javascript">
var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="lokal" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')

Die Fehlermeldung:
Error Line 26 column 23: end tag for element "STYLE" which is not open.
document.write('</style>\n')
The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.

So wie ich das verstanden habe meckert er ein End-Tag an welches er nicht als geöffnet erkennt. Nun soll doch aber dieses end-Tag erst mit JS geschrieben werden. Da ich JS-technisch nicht gerade der hellste bin würde ich mich über eine kleine hilfe freuen.


Hier das validierte Script


Gruß Ronny


}
 
QUOTE (ronnic @ Mi 2.8.2006, 8:34)document.write('</style>\n')

Einfach den Code eine Winzigkeit abändern bzw. das Element zerlegen:


CODE document.write('<' + '/' + 'style>\n')


Das müßte eigentlich schon helfen.

Insgesamt bessere Alternative: Den Code in eine externe Datei auslagern, dann kriegt der Validator das nicht mit.

Da hat der Validator eine gewisse Schwäche.
 
Zurück
Oben