Open In App

HTML DOM Script type Property

The DOM Script type Property is used to set or return the value of the type attribute of a <script> element. The type attribute is used to specify the MIME type of a script. and identify the content of the <script> Tag. It has a Default value which is “text/javascript”

Syntax: 



scriptObject.type 
scriptObject.type = MIME_type 

Property Values: It contains the value i.e. MIME type which specifies the MIME type of a script. 

Common Values: 



Return Values: It returns a string value that represents the MIME type of a script. 

Example 1: This Example illustrates to return the Type Property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM script type Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
    <h2>
        DOM script type property
    </h2>
   
    <script id="myGeeks" type="text/javascript">
        document.write("Hello GeeksForGeeks");
    </script>
   
    <br>
    <br>
    <button onclick="Geeks()">
          Submit
      </button>
    <h2 id="demo"></h2>
   
    <script>
        function Geeks() {
           let x =
               document.getElementById("myGeeks").type;
            document.getElementById("demo")
            .innerHTML = x;
        }
    </script>
 
</body>
 
</html>

Output:

 

Example 2: This Example illustrates to set the Type Property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM script type Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
    <h2>
        DOM script type property
    </h2>
    <script id="myGeeks" type="text/javascript">
        document.write("Hello GeeksForGeeks");
    </script>
    <br>
    <br>
    <button onclick="Geeks()">
          Submit
      </button>
    <h2 id="demo"></h2>
   
    <script>
        function Geeks() {
            let x =
                document.getElementById("myGeeks").type =
                "MIME_type ";
            document.getElementById("demo").innerHTML = x;
        }
    </script>
 
</body>
 
</html>

Output: 

 

Supported Browsers: The browsers supported by DOM script type property are listed below:


Article Tags :