Open In App

HTML DOM Script text Property

Last Updated : 21 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML DOM Script text Property is used to set or return the content of the <script> element

Syntax: 

  • It Returns the text property:
scriptObject.text
  • It is used to set the text property:
scriptObject.text = contents 

Property Values: It contains the value i.e contents that specify the content of the <script> element. 

Return Values: It returns a string value that represents the content of the script element. i.e. all the Text nodes of the script but ignore the comments. 

Example 1: This Example is used to return the text Property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM script text Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
    <h2>
        DOM script Text 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").text;
            document.getElementById("demo").innerHTML =
                x;
        }
    </script>
 
</body>
 
</html>


Output: 

 

Example 2: This Example is used to set the text Property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        DOM script text Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
 
    <h2>
        DOM script Text 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").text =
                "Script Content will be changed now";
            document.getElementById("demo").innerHTML = x;
        }
    </script>
 
</body>
 
</html>


Output:

 

Supported Browsers: The browsers supported by HTML | DOM Script text Property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer
  • Firefox 1 and above
  • Apple Safari
  • Opera


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads