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?
<script />
is valid XML, but invalid HTML.
If you serve your pages as text/xml the browser will correctly load them.
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.
Script tags simply cannot be self-closing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With