Does the script tag> contain a separate </script> tag?

Today I noticed that when I try to close my <script> it makes or breaks my page. For example, this works:

 <script src="scripts/jquery.js" type="text/javascript"></script> 

but this is not so:

 <script src="scripts/jquery.js" type="text/javascript" /> 

The file appears when I use IE Developer Tools, but it looks like it is simply ignored. Has anyone seen this or knew why this could happen? Thanks in advance!

+7
source share
3 answers

You must include the closing tag of the script . The script element does not close by itself, even if you include only the external script.

+14
source

The <script> can only be self-closing in really accessible XHTML documents - that is, the XHTML page contained with Content-Type of application/xhtml+xml - and when viewed in a supporting browser (IE8 does not work, IE9 + does).

In all other HTML documents ( no matter what DOCTYPE declared), the <script> not self-closing, so a </script> must be closed.

More details in this very detailed answer.

+7
source

I also noticed that you always need </script> . Probably because it requires content between tags ("count"), even if you use src .

+2
source

All Articles