views:

75

answers:

4

What is the the difference in writing different Script tags like <script>.... or <script language="javascript">..... or <script type="text/javascript">...........?

They all do same things, what is different?

A: 

<script> can contain more than just Javascript. It can hold many type of other scripts like VbScript, classic ASP script, c#, even PHP.

  1. <script> means you are writing a script

  2. <script language="......"> defines the language in which you are going to write your script

  3. <script type="........."> defines the content-Type of your script

Starx
@thedownvoter, please some comment.
Starx
Not my downvote, but a) asker is not confused and b) they are "different style script tags" in the *English* sense of the word 'style'. And c) your point #3 refers to 'format' which isn't a thing.
AakashM
1. No, that isn't it at all. 2. Kinda. 3. Not really.
David Dorward
@David Dorward, Is my answer correct now?
Starx
@Starx, I think I know the differences now, and I know what I should use, due to @David's answers
Starx
+4  A: 

According to w3c spec, type attribute is required, and determines script language, whereas language attribute (which does more or less the same) is deprecated in favor of type, so you should use type attribute.

el.pescado
I am rather asking about the difference than which is preferred? Thanks though
Starx
@meusi, see my answer I have included the difference
Starx
+1  A: 

In HTML 4.01 the type attribute is required. http://www.w3.org/TR/REC-html40/interact/scripts.html#adef-type-SCRIPT

In practice though, all commonly used browsers default this to text/javascript, so there isn't really a need to specify it unless you care about validators or older versions of IE. The HTML5 spec makes it optional. http://www.whatwg.org/specs/web-apps/current-work/#attr-script-type

Alex M.
I am rather asking about the difference than which is preferred? Thanks though
Starx
+3  A: 

<script language="javascript">

HTML 3.2 — The first attempt

<script type="text/javascript">

HTML 4.x and XHTML 1.x — using MIME types for everything. This is the current standard. Use this.

<script>

HTML 5 (draft) — "Ah, too many authors don't care, browsers error recover from it anyway, lets all but give up on the possibility other other embedded scripting languages being used"

David Dorward