It all started…

So, I was thinking on my way home how clunky wanting to add text to a page with JavaScript. My use-case is this: I want to add the current year to my page. But because I’m just using HTML, I don’t have any server-side ability to add this. So I’m using:

<span id="thisYear"></span>

And then later…

<script type="text/javascript">
// set copyright year
$("#thisYear").text(new Date().getFullYear());
</script>

So I wanted a different way to do it. I looked at using an empty tag (<var id=”thisYear” />) but Firefox doesn’t seem to like that, because it was swallowing up text behind that. I did a search for empty tags and found this article on empty elements.

The question arises whether “Tags for Empty Elements” in XML, i.e. things like <hr /> (or <hr />), really comply with SGML rules. The SGML Handbook seems to say they don’t. The start tag syntax there (p. 314) says that between the tag name (“generic identifier” in SGML terminology) and the closing “>” (“tagc”, for tag close), only attribute specifications and whitespace is allowed.

So it seems that XML empty tags don’t really comply with SGML rules!
So what is Firefox really doing?

Leave a Reply

Your email address will not be published. Required fields are marked *