HTML | DOM Script text Property

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:
Before Clicking On Button:

.
After Clicking On Button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


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
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.