The code is like this:
var script = document.createElement('script');
//script.type = 'text/javascript'; // do I need this ?
script.src = src;
document.body.appendChild(script);
The second line has been commented out because it makes no difference to have it. Or am I missing something ?
Thanks,
No: The default value of type
is already set to JavaScript ("text/javascript"). The type attribute is a property of the SCRIPT tag to allow Vbscript, for example, which is only supported by IE.
The type
attribute has also become optional in HTML5. This could be an encouragement to omit the type
attribute of the script
element.
No. It's probably not strictly correct in html4 but it shouldn't cause you any problems.
HTML5 Spec
"The type attribute gives the language of the script or format of the data..."
"...The default, which is used if the attribute is absent, is 'text/javascript'."
The only thing I have noticed is that IDE's sometimes don't use the correct syntax highlighting when you don't specify a type. I have found this in Coda for the Mac, it's the only reason I ever put it in now.
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