Script type Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Script


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

The type attribute sets the MIME type of a script, which identifies the content between the <script> and </script> tags.

The MIME type consists of two parts: one media type and one subtype.

For JavaScript, the MIME type is "text/javascript".

In HTML5, the type attribute is no longer required.

The default value is "text/javascript".

Set the type property with the following Values

Value Description
MIME_type Sets the MIME type of the script.

Some common values:

text/javascript (Default) 

Return Value

A String, representing the MIME type of the script

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<script id="myScript" type="text/javascript">
document.write("Hello World!");
</script>/* w  ww . j a  v a2  s .  co  m*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("myScript").type;
    document.getElementById("demo").innerHTML = x;


Related Tutorials