What is the doctype of your document? Technically minimized tags like your first example are an XML-only thing. In most cases HTML allow them, but the correct HTML is your second example.
+2
A:
Licky Lindsay
2009-08-19 00:45:38
+3
A:
Yeah, you always need to end script elements like that. It doesn't support the XHTML format of ' />' to end the tag.
Noon Silk
2009-08-19 00:46:09
I've noticed this was the case, and now close all js-related tags this way, but is there any particular reason? I'm aware it's probably a duplicate question, but that's why this is just a comment.
Marc Bollinger
2009-08-19 01:06:46
I don't know exactly, but my guess would be it's due to compatibility. Quirksmode has some info : http://www.quirksmode.org/bugreports/archives/2006/06/MSIE_script_tag_failure_in_valid_xhtml.html
Noon Silk
2009-08-19 01:08:55
Technically the `/>` format is valid in XHTML, but never in HTML—well, it actually has an obscure, rarely-implemented meaning. And even if you think you’re writing XHTML, odds are it’s being served as `text/html` and so the browser is treating it as HTML. The fact that tags like `<br />` work (the HTML version is just `<br>` with no closing tag) is only because HTML parsers are forgiving.
Nate
2009-08-19 02:12:03
If an element has an empty content model then the XML empty-element syntax is acceptable. If an element does *not* have an empty content model, the XML syntax is not acceptable. Check the HTML 4.01 or XHTML 1.0 DTDs for details of which elements have an empty content model.
NickFitz
2009-08-19 09:35:47
+1
A:
Certain elements like script
and iframe
dont work correctly in all browsers unless you have a closing tag, even if there is no content inside. While I agree that this is stupid, its just one more of those inconsistencies that web developers need to be aware of.
I would imagine that once browser vendors implement actual XHTML (so we can send XHMTL as application/xhtml+xml not text/html) that at that point they would also fix inconsistencies like this. Or maybe I'm just an optimist.
Darko Z
2009-08-19 01:25:31