I'd like to include a javascript file on every page of a site. I can do this with:
<script type="text/javascript" src="myFile.js" ></script>
This works fine - however as there's nothing between the two tags, I wanted to change it to:
<script type="text/javascript" src="myFile.js" />
If I do this, it doesn't work - nothing after that line loads on the page.
Any ideas why? Thanks
Unfortunately, the HTML specs for REQUIRE a closing tag...
HTML Standard, section 18.2.1
18.2.1 The SCRIPT element
Start tag: required, End tag: required
This is not a bug, it's standard behavior.
Also, empty HTML elements are often not rendered:
<div style="background:red"></div>
displays, <div style="background:red" />
doesn't
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