I noticed today while doing some testing that the way I close my <script>
tag either makes or breaks my page. For example, this works:
<script src="scripts/jquery.js" type="text/javascript"></script>
but this does not:
<script src="scripts/jquery.js" type="text/javascript" />
The file appears to show up when I use IE's Developer Tools, but it seems like it just gets ignored. Has anyone ever seen this or know why it might be happening? Thanks in advance!
I noticed today while doing some testing that the way I close my <script>
tag either makes or breaks my page. For example, this works:
<script src="scripts/jquery.js" type="text/javascript"></script>
but this does not:
<script src="scripts/jquery.js" type="text/javascript" />
The file appears to show up when I use IE's Developer Tools, but it seems like it just gets ignored. Has anyone ever seen this or know why it might be happening? Thanks in advance!
Share Improve this question edited Dec 13, 2013 at 22:19 lhan asked May 26, 2011 at 21:08 lhanlhan 4,63513 gold badges62 silver badges108 bronze badges 03 Answers
Reset to default 14You must include a closing script tag. The script element is not self closing, even when you're only including an external script.
The <script>
tag can only be self-closing in truly valid XHTML documents – that is, a XHTML page served with the Content-Type
of application/xhtml+xml
– and when viewed in a supporting browser (IE8 does not qualify; IE9+ does).
In all other HTML documents, (regardless of what DOCTYPE
is declared), the <script>
tag is not self-closing and therefore must be closed with a </script>
.
Read more in this very detailed answer.
I have also noticed you always need the </script>
. It's probably because it requires content between the tags ("" counts), even though you're using src
.