David
28th Nov 2005, 03:05 pm
I learned something new today when I tested a file for XHTML 1.0 Strict validation.
The file contained a small script that had some embedded markup like so:
<script type="text/javascript">
document.writeln("<p class='day'>" + darr[now.getDay()] + "</p><p>"
+ now.getDate()
+ "<sup>" + narr[now.getDate()] + "</sup>"
+ " " + marr[now.getMonth()]
+ " " + now.getFullYear() + "</p>");
</script>
All this code does is to print the date and the paragraph tags are embedded within the script - it's a neat way of doing it because the whole thing is contained in a single script.
However, it appears that this is not valid XHTML 1.0 Strict - there should be no embedded tags within scripts. So, I had to change the code to this in order to comply:
<p class="day">
<script type="text/javascript">
document.writeln(darr[now.getDay()]);
</script>
</p><p>
<script type="text/javascript">
document.writeln([now.getDate()]
+ narr[now.getDate()]
+ " " + marr[now.getMonth()]
+ " " + now.getFullYear());
</script>
</p>
Notice that this requires two scripts rather than one. In fact, I couldn't be bothered coding for the superscript - that would have required 4 scripts! Still, at least it is now valid code.
I'm still not entirely sure of the logic behind this but it's worth bearing in mind if you do include any javascript in your pages.
The file contained a small script that had some embedded markup like so:
<script type="text/javascript">
document.writeln("<p class='day'>" + darr[now.getDay()] + "</p><p>"
+ now.getDate()
+ "<sup>" + narr[now.getDate()] + "</sup>"
+ " " + marr[now.getMonth()]
+ " " + now.getFullYear() + "</p>");
</script>
All this code does is to print the date and the paragraph tags are embedded within the script - it's a neat way of doing it because the whole thing is contained in a single script.
However, it appears that this is not valid XHTML 1.0 Strict - there should be no embedded tags within scripts. So, I had to change the code to this in order to comply:
<p class="day">
<script type="text/javascript">
document.writeln(darr[now.getDay()]);
</script>
</p><p>
<script type="text/javascript">
document.writeln([now.getDate()]
+ narr[now.getDate()]
+ " " + marr[now.getMonth()]
+ " " + now.getFullYear());
</script>
</p>
Notice that this requires two scripts rather than one. In fact, I couldn't be bothered coding for the superscript - that would have required 4 scripts! Still, at least it is now valid code.
I'm still not entirely sure of the logic behind this but it's worth bearing in mind if you do include any javascript in your pages.