Forum Moderators: phranque
Just made a little website for an NGO. It was so simple, so I decided I can code it by hand as in the old days:) Then validated it via W3c's Validator, and ALL was OK, except for a little strange thing. I use small JavaScipt in my page, which takes the TITLE of the page in the HEAD part of the html file, and writes it somewhere down in the page, so I can omit the retyping of the title in two places.
Here's the script:
<script language="JavaScript" type="text/javascript">
<!--
document.write('<span class="titlePage">[ ');
document.write(document.title +' ]</span>');
//-->
</script>
The class I use so the text appears in my desired font-family and font-size.
The script produces smth like this:
"
[ Our NGO - You are on the following page ]
"
(title in HEAD is "Our NGO - You are on the following page"), and in all browsers I tested it produces equal results - all's OK.
But when validated (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> - doctype I put in the HEAD), the Validator shows the following:
Line 113, column 40: end tag for element "SPAN" which is not open (explain...).
document.write(document.title +' ]</span>');
^
OK. But the SPAN opening tag is on previous line, and this script works FINE, even in Netscape 4.x, which is pretty old. I don't know JavaScript, only html and css. All the page is OK, except for this fault. Am I missing smth.? Should I worry about it? It's only this, but to be perfect I need to fix this, too... :-)
If someone can point me to the mistake in this script or what I can correct so the code is 100% OK, I'll be very grateful!:)))
Sincerely, M.
You can escape the "/" with the "\" character:
document.write(document.title +' ]<\/span>');
And don't forget document.write can take multiple arguments. Sometimes it's clearer to write:
document.write(document.title, ' ]<\/span>');
Nick