views:

76

answers:

2
+2  Q: 

html script tag

Hi,

Why doesn't this work

<script src="jquery.js"/>

But this works

<script src="jquery.js"></script>

?

Firefox 3.5.8

+6  A: 
cletus
will the /> trick work (in modern browsers) if the pages Content-Type header is application/xml? I've heard of such black magic before.
jdizzle
@jdizzle `/>` will work if its an XHTML document, which has several ramifications. It has problems with older browsers and (imho) there's no compelling reason to use XHTML so just don't do it would be my advice.
cletus
A: 

The script element is not defined as EMPTY (since you can embed the script directly inside it), therefore in HTML the end tag is required, therefore you cannot have something that is (in tag soup terms) a start tag with a random / character in it representing the entire element.

Hence we have: http://www.w3.org/TR/xhtml-media-types/#C_2

David Dorward