Morais
Morais

Reputation: 801

<script type="text/javascript">

Is there any difference between

<script type="text/javascript">

and

<script>

tags ?

Upvotes: 2

Views: 3455

Answers (5)

GG.
GG.

Reputation: 21854

According to CSS-Tricks:

<script type="text/javascript">
  //some javascript here
</script>

The type attribute is the standard and correct way to identify and tell the browser what kind of script the tag contains. Sometimes you'll see code that uses both the language and type attribute. As far as I know that's never necessary.

Really specific explanation from the spec, language is an "obsolete but conforming" feature.

but

<script>
  //some javascript here
</script>

No attributes at all. This is the HTML5 way of handling script tags that contain JavaScript. It's just assumed that the type is text/javascript. If it's not (I've never even seen a different type of script) you'll need to change it with the type attribute. I recommend this is you are using HTML5.

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163288

The type attribute is no longer a required attribute in most browsers.

From MDC:

type

This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript. If this attribute is absent, the script is treated as JavaScript.

Upvotes: 3

ArK
ArK

Reputation: 21068

As per W3C standard its essential. As HTML does not rely on a specific scripting language, document authors must explicitly tell user agents the language of each script. This may be done either through a default declaration or a local declaration.

Upvotes: 0

subosito
subosito

Reputation: 3470

There is no difference between those two tags. Prior to HTML5 you need to explicitly add 'text/javascript'. On HTML5 you can skip that part.

Upvotes: 1

nico
nico

Reputation: 51670

Most browsers will default type to text/javascript, but other values are allowed, see

http://www.w3schools.com/tags/tag_script.asp

Also, as for W3C specifications

As HTML does not rely on a specific scripting language, document authors must explicitly tell user agents the language of each script. This may be done either through a default declaration or a local declaration.

Upvotes: -1

Related Questions