Javascript Reference - HTML DOM Script type Property








The type attribute specifies the MIME type of a script.

The type property sets or gets the type attribute of a script.

Browser Support

type Yes Yes Yes Yes Yes

Syntax

Return the type property.

var v = scriptObject.type

Set the type property.

scriptObject.type=MIME_type




Property Values

Value Description
MIME_type Specifies the MIME type of the script.

Some common values:
  • text/javascript, This is default value.
  • text/ecmascript
  • application/ecmascript
  • application/javascript
  • text/vbscript

Return Value

A String type value representing the MIME type of the script.

Example

The following code shows how to get the MIME type of a script.


<!DOCTYPE html>
<html>
<body>
<!--from   www .ja  va2s . c  o  m-->
<script id="myScript" type="text/javascript">
document.write("Hello World!");
</script>
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myScript").type;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: