I had this code in my website
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"/>
<script type='text/javascript' src='/lib/player/swfobject.js'></script>
swfobject was not working (not loaded).
After altering the code to:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type='text/javascript' src='/lib/player/swfobject.js'></script>
It worked fine.
The document was parsed as HTML5.
I think it’s funny. Okay, granted a tag that is closed and a self-closing tag are not the same. So I would understand if jQuery couldn’t load (although I find it ridiciulous).
But what I do not understand is that jQuery loads but the following, correctly written tag, doesn’t?
In HTML, there are tags which are always self-closed. For example,
<hr>Some content here</hr>
does not make any sense. In the same way, there are tags which cannot be self-closed.<script>
tag is one of them.I am not sure about the reason of no self-closed
<script>
tags, but the reason might come from the fact that the tag was intended to always contain code inside. Again, I'm not sure.Because it gets parsed as:
Line 1: Start tag for script
Line 2: JavaScript (really broken JavaScript!) to execute if the external script mentioned on line 1 fails to load
Line 3: End tag for script started on line 1
They are the same (if there is no content), but only in XML documents. An XHTML document served as application/xhtml+xml is an XML document. In an HTML document, thanks to a legacy of improper implementations by browsers, a self-closing tag is just a start tag (and so is only OK when the end tag is forbidden).
@Joe Hopfgartner: Did you alter the code to test if
works? ;-)
Update:
Run the code and the
<p>
element gets hidden, so...looks like it works?HTML
JavaScript (4531772.js)
David Dorward's answer explains this from one angle, but there is a deeper reason why you can't do this:
A slash at the end of a tag does not make it self-closing in HTML
The self-closing syntax is part of XML. In a normal HTML document, it has no meaning.