views:

95

answers:

3
+2  A: 

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.

Licky Lindsay
+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
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
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
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
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
+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
Good luck with that, with HTML5 out, XHTML will most likely NEVER reach that point.
micmcg
AFAIK they've only suspended work on XHTML2 until HTML5 is done, though I sympathize with your pessimism :)
Darko Z