Skip to content
Related Articles

Related Articles

HTML | DOM Script text Property

View Discussion
Improve Article
Save Article
  • Last Updated : 28 Jul, 2022

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 which specify the content of the <script> element. 

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

Example: This Example 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() {
            var x =
                document.getElementById("myGeeks").text;
            document.getElementById("demo").innerHTML =
              x;
        }
    </script>
 
</body>
 
</html>

Output: Before Clicking On Button:

 

After Clicking On Button:

  

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() {
            var x = document.getElementById(
              "myGeeks").text = "Script Content will be changed now";
            document.getElementById("demo").innerHTML = x;
        }
    </script>
 
</body>
 
</html>

Output: Before Clicking On Button:

  

After Clicking On Button:

  

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!