For example here the code goes like this:
<html lang="en">
<head>
<!-- whatever -->
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<!-- whatever -->
Note that <script>
should have contained type
attribute (perhaps set to "text/javascript"
) but it is not present here.
This is not the only example I've seen. Such code makes Visual Studio editor unhappy - it underlines <script>
and says there should be a type
attribute. It also makes me curious big time.
Why is type
often omitted? What happens if I add type="text/javascript"
- will jQuery break or something?
That's probably because HTML5 does not require a type
attribute on <script>
elements (it defaults to "text/javascript"
).
In HTML 5 it's now set by default that the script will be of type JavaScript, so there's no need to specify it. HTML 4.01 does require it though, it seems.
See here: http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1
And: http://www.w3.org/TR/html5/scripting-1.html#script
It is no longer a requirement in html5.
http://www.w3.org/html/wg/drafts/html/master/scripting-1.html
The type
tag is optional.
Default programming languages in all browsers has been JavaScript so that is what it defaults to. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out.
The browsers will know it is Javascript.
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