and not
Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why <script></script> and not <script /> in HTML5?

Why the following line is not working in many browsers (mozilla, IE)?

<script src="jQuery.js" />

Why we must set it like this?

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

These days I convert my project from XHTML to HTML5 and I face some minor but disturbing incombatibilities.

like image 739
Chameleon Avatar asked Jun 20 '26 11:06

Chameleon


1 Answers

While a script element can have the content loaded from an external URL via the src attribute, it can also have the code inline (as a child node). This means it is not an EMPTY element so can't require that the end tag be omitted.

In HTML 5 the / at the end of a start tag does not mean "This is a self-closing tag", it is just syntactic sugar for people who have written too much XML or are using XML syntax highlighters.

Even if you were still writing XHTML, you probably couldn't use the <script /> syntax as it is not HTML compatible.

like image 140
Quentin Avatar answered Jun 22 '26 23:06

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!