Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

closing tag in HTML [duplicate]

Possible Duplicate:
Why don't self-closing script tags work?

I'm trying jquery now. When I included the jquery.js as follows

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

the code doesn't worked properly. Actually it is just a simple hello world program. I just called a jQuery specific function. But that was not working if I include the file as above. But when I changed the closing like this

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

the code worked well. What is the difference?

like image 769
theB Avatar asked Mar 02 '12 06:03

theB


3 Answers

<script /> is valid XML, but invalid HTML.

If you serve your pages as text/xml the browser will correctly load them.

like image 196
Frankie Avatar answered Sep 27 '22 18:09

Frankie


Before anyone else mentions it, HTML is NOT XHTML. It's not even a subset. HTML evolved out of SGML and it has its own rules. One of those rules is that certain tags need to be closed and certain tags don't. There's actually no such thing as <script /> or even <br />, that's an XML concept and they really don't belong in HTML at all.

The only reason these things sometimes work is because page authors do things wrong and some browsers try to be nice about it.

like image 25
SpliFF Avatar answered Sep 27 '22 18:09

SpliFF


Script tags simply cannot be self-closing.

like image 40
Arie van Someren Avatar answered Sep 27 '22 18:09

Arie van Someren