Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  61] [ 6]  / answers: 1 / hits: 123699  / 15 Years ago, mon, february 15, 2010, 12:00:00
<script type=text/javascript>
/* ... */
</script>


vs.



<script language=Javascript>
/* ... */
</script>


Which should be used and why?



Or, the third alternative: omitting either of these, such as the example code in jQuery's API reference:



<script src=http://code.jquery.com/jquery-latest.js></script>

More From » html

 Answers
36

The language attribute has been deprecated for a long time, and should not be used.



When W3C was working on HTML5, they discovered all browsers have text/javascript as the default script type, so they standardized it to be the default value. Hence, you don't need type either.



For pages in XHTML 1.0 or HTML 4.01 omitting type is considered invalid. Try validating the following:



<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml xml:lang=en lang=en>
<head>
<script src=http://example.com/test.js></script>
</head>
<body/>
</html>


You will be informed of the following error:




Line 4, Column 41: required attribute type not specified




So if you're a fan of standards, use it. It should have no practical effect, but, when in doubt, may as well go by the spec.


[#97565] Friday, February 12, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clarkulisesa

Total Points: 422
Total Questions: 93
Total Answers: 112

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
clarkulisesa questions
Mon, Feb 24, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;