Script type attribute

Definition and usage

type Attribute sets or returns the script's Type attribute Value.

The type attribute specifies the MIME type of the script.

The type attribute identifies the content between the <script> and </script> tags.

MIME types consist of two parts: a media type and a subtype. For JavaScript, the MIME type is "text/javascript".

Note:In HTML5, the type attribute is no longer needed. The default value is "text/javascript".

See also:

HTML Reference Manual:HTML <script> type Attribute

HTML Reference Manual:HTML <script> Tag

Example

Get the MIME type of the script:

var x = document.getElementById("myScript").type

Try it yourself

Syntax

Return the type attribute:

scriptObject.type

Set the type attribute:

scriptObject.type = MIME_type

Attribute value

Value Description
MIME_type

Specifies the MIME type of the script.

Common values:

  • text/javascript (default)
  • text/ecmascript
  • application/ecmascript
  • application/javascript

Please see IANA MIME Types, to get a complete list of standard MIME types.

Technical Details

Return Value: A string value representing the MIME type of the script.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support