Tuesday, December 14, 2010

<script> tag: type="text/javascript" vs language="javascript"

When adding JavaScript to a webpage using the <script> tags, should you use the type attribute, the language attribute or both? The answer is below...
<script type="text/javascript"></script>
OR
<script language="javascript"></script>
OR
<script language="javascript" type="text/javascript"></script>
The simple answer is you should be using the type attribute for script tags
<script type="text/javascript"></script>

You do not need to use the language attribute because the attribute has been deprecated since HTML 4.01, this can be seen in the "Designing documents for user agents that support scripting" section in the HTML 4.01 Specification.

No comments: